core.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. class Booked_WC {
  3. private function __construct() {
  4. if ( $this->check_plugin_dependencies() ) {
  5. $this->setup_woocommerce_support();
  6. $this->setup_booked_custom_fields();
  7. $this->enqueue_scripts();
  8. $this->wp_ajax();
  9. $this->filters_and_actions();
  10. $this->add_new_post_status();
  11. $this->add_options_pages();
  12. $this->setup_wp_cron();
  13. }
  14. }
  15. public static function setup() {
  16. return new self();
  17. }
  18. protected function check_plugin_dependencies() {
  19. $booked_exists = class_exists('booked_plugin');
  20. $woocommerce_exists = class_exists('WooCommerce');
  21. if (!$booked_exists || !$woocommerce_exists) {
  22. Booked_WC_Notice::add_notice(
  23. __('"Booked Payments with WooCommerce" plugin by Boxy Studio is currently inactive due to a missing dependency.', 'booked-woocommerce-payments'),
  24. 'error'
  25. );
  26. }
  27. if ( !$booked_exists ) {
  28. Booked_WC_Notice::add_notice(
  29. __('"Booked" plugin by <a href="https://boxystudio.com/" target="_blank">Boxy Studio</a> is missing or not active.', 'booked-woocommerce-payments'),
  30. 'error'
  31. );
  32. }
  33. if ( !$woocommerce_exists ) {
  34. Booked_WC_Notice::add_notice(
  35. __('"WooCommerce" plugin by <a href="http://www.woothemes.com/woocommerce/" target="_blank">WooThemes</a> is missing or not active.', 'booked-woocommerce-payments'),
  36. 'error'
  37. );
  38. }
  39. return $booked_exists && $woocommerce_exists;
  40. }
  41. protected function filters_and_actions() {
  42. # ------------------
  43. # Filters
  44. # ------------------
  45. add_filter('booked_mailer_actions', array('Booked_WC_Functions', 'booked_wc_mailer_actions'), 10, 1 );
  46. add_filter('booked_prepare_sending_reminder', array('Booked_WC_Functions', 'booked_prepare_sending_reminder'), 10, 2);
  47. add_filter('booked_custom_field_data', array('Booked_WC_Functions', 'booked_custom_field_data'), 10, 1);
  48. add_filter('booked_appointments_array', array('Booked_WC_Functions', 'booked_appointments_array'), 10, 1);
  49. add_filter('booked_button_book_appointment', array('Booked_WC_Functions', 'booked_button_book_appointment'), 10, 1);
  50. add_filter('booked_shortcode_appointments_allow_cancel', array('Booked_WC_Functions', 'booked_shortcode_appointments_allow_cancel'), 10, 2);
  51. add_filter('booked_admin_pending_post_status',array('Booked_WC_Functions', 'booked_admin_pending_post_status'), 10, 2);
  52. add_filter('booked_fea_shortcode_appointments_buttons', array('Booked_WC_Functions', 'booked_fea_shortcode_appointments_buttons'), 10, 2);
  53. add_filter('woocommerce_cart_item_name', array('Booked_WC_Cart_Hooks', 'woocommerce_cart_item_name'), 10, 3);
  54. add_filter('woocommerce_cart_item_thumbnail', array('Booked_WC_Cart_Hooks', 'woocommerce_cart_item_thumbnail'), 10, 2 );
  55. add_filter('woocommerce_checkout_cart_item_quantity', array('Booked_WC_Cart_Hooks', 'woocommerce_checkout_cart_item_quantity'), 10, 3 );
  56. add_filter('woocommerce_order_item_name', array('Booked_WC_Order_Item_Hooks', 'woocommerce_order_item_name'), 10, 2);
  57. add_filter('woocommerce_attribute_label', array('Booked_WC_Order_Item_Hooks', 'woocommerce_attribute_label'), 10, 3);
  58. add_filter('woocommerce_hidden_order_itemmeta', array('Booked_WC_Order_Hooks', 'woocommerce_hidden_order_itemmeta'), 10);
  59. add_filter('woocommerce_order_items_meta_display', array('Booked_WC_Order_Hooks', 'woocommerce_order_items_meta_display'), 10, 2);
  60. # ------------------
  61. # Actions
  62. # ------------------
  63. add_action('wp_loaded', array('Booked_WC_Cart_Hooks', 'woocommerce_remove_missing_appointment_products'), 10, 1);
  64. add_action('woocommerce_resume_order', array('Booked_WC_Order_Hooks', 'woocommerce_validate_order_items'), 10, 1);
  65. add_action('woocommerce_new_order', array('Booked_WC_Order_Hooks', 'woocommerce_validate_order_items'), 10, 1);
  66. add_action('wp_ajax_booked_new_appointment_form', array('Booked_WC_Functions', 'booked_new_appointment_form'), 5);
  67. add_action('wp_ajax_nopriv_booked_new_appointment_form', array('Booked_WC_Functions', 'booked_new_appointment_form'), 5);
  68. add_action('booked_new_appointment_created', array('Booked_WC_Functions', 'booked_new_appointment_created'), 15, 1);
  69. add_action('booked_new_appointment_created', array('Booked_WC_Functions', 'booked_store_appointment_creation_date'), 10, 1);
  70. add_action('booked_before_creating_appointment', array('Booked_WC_Functions', 'remove_default_emails'), 1);
  71. add_action('booked_before_creating_appointment', array('Booked_WC_Functions', 'booked_before_creating_appointment'), 10);
  72. // On Order Complete
  73. add_action('woocommerce_order_status_completed', array('Booked_WC_Order_Hooks', 'woocommerce_order_complete'), 10, 1);
  74. // Trash the appointment on order cancel, refunded or deleted
  75. add_action('woocommerce_order_status_cancelled', array('Booked_WC_Order_Hooks', 'woocommerce_order_remove_appointment'), 10, 1);
  76. add_action('woocommerce_order_status_refunded', array('Booked_WC_Order_Hooks', 'woocommerce_order_remove_appointment'), 10, 1);
  77. add_action('woocommerce_order_status_trash', array('Booked_WC_Order_Hooks', 'woocommerce_order_remove_appointment'), 10, 1);
  78. add_action('before_delete_post', array('Booked_WC_Order_Hooks', 'woocommerce_order_remove_appointment'), 10, 1);
  79. add_action('booked_admin_calendar_buttons_after', array('Booked_WC_Functions', 'booked_admin_calendar_buttons_after'), 10, 3);
  80. add_action('booked_admin_calendar_buttons_before', array('Booked_WC_Functions', 'booked_admin_calendar_buttons_before'), 10, 3);
  81. add_action('booked_shortcode_appointments_buttons', array('Booked_WC_Functions', 'booked_shortcode_appointments_buttons'), 10, 1);
  82. add_action('booked_shortcode_appointments_additional_information', array('Booked_WC_Functions', 'booked_shortcode_appointments_additional_information'), 10, 1);
  83. add_action('woocommerce_add_order_item_meta', array('Booked_WC_Order_Hooks', 'woocommerce_add_order_item_meta'), 10, 4);
  84. }
  85. protected function setup_woocommerce_support() {
  86. Booked_WC_Main::setup();
  87. }
  88. protected function setup_booked_custom_fields() {
  89. Booked_WC_Custom_Fields::setup();
  90. }
  91. protected function enqueue_scripts() {
  92. Booked_WC_EnqueueScript::enqueue();
  93. }
  94. protected function wp_ajax() {
  95. Booked_WC_Ajax::setup();
  96. }
  97. protected function add_new_post_status() {
  98. Booked_WC_Post_Status::setup();
  99. }
  100. protected function add_options_pages() {
  101. Booked_WC_Settings::setup();
  102. }
  103. protected function setup_wp_cron() {
  104. Booked_WC_WP_Crons::setup();
  105. }
  106. }