class-enqueue-scripts.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. class Booked_WC_EnqueueScript {
  3. protected $prefix;
  4. protected $plugin_url;
  5. private function __construct() {
  6. $this->prefix = BOOKED_WC_PLUGIN_PREFIX;
  7. $this->plugin_url = BOOKED_WC_PLUGIN_URL;
  8. add_action('wp_enqueue_scripts', array($this, 'enqueue_front_end_script'));
  9. add_action('admin_enqueue_scripts', array($this, 'enqueue_back_end_script'));
  10. }
  11. public static function enqueue() {
  12. return new self();
  13. }
  14. public function add_js_variables() {
  15. $redirect_page = Booked_WC_Settings::get_option('redirect_page');
  16. if ( $redirect_page == 'cart' ):
  17. $checkout_page_id = Booked_WC_Helper::get_cart_page();
  18. else:
  19. $checkout_page_id = Booked_WC_Helper::get_checkout_page();
  20. endif;
  21. $checkout_page_link = get_permalink( $checkout_page_id );
  22. $checkout_page_link = apply_filters( 'booked_wc_redirect_url', $checkout_page_link );
  23. $js_variables_array = array(
  24. 'prefix' => BOOKED_WC_PLUGIN_PREFIX,
  25. 'ajaxurl' => admin_url('admin-ajax.php'),
  26. 'i18n_confirm_appt_edit' => __('Are you sure you want to change the appointment date? By doing so, the appointment date will need to be approved again.', 'booked-woocommerce-payments'),
  27. 'i18n_pay' => __('Are you sure you want to add the appointment to cart and go to checkout?', 'booked-woocommerce-payments'),
  28. 'i18n_mark_paid' => __('Are you sure you want to mark this appointment as "Paid"?', 'booked-woocommerce-payments'),
  29. 'i18n_paid' => __('Paid', 'booked-woocommerce-payments'),
  30. 'i18n_awaiting_payment' => __('Awaiting Payment', 'booked-woocommerce-payments'),
  31. 'checkout_page' => $checkout_page_link
  32. );
  33. $default_post_status = get_option('booked_new_appointment_default','draft');
  34. if ($default_post_status != 'draft'):
  35. $js_variables_array['i18n_confirm_appt_edit'] = false;
  36. endif;
  37. wp_localize_script( 'booked-wc-fe-functions', 'booked_wc_variables', $js_variables_array );
  38. wp_localize_script( 'booked-wc-admin-functions', 'booked_wc_variables', $js_variables_array );
  39. }
  40. public function enqueue_front_end_script() {
  41. if ( !is_admin() ):
  42. wp_register_script( 'booked-wc-fe-functions', $this->plugin_url . '/js/frontend-functions.js', array('jquery') );
  43. wp_enqueue_style( 'booked-wc-fe-styles', $this->plugin_url . '/css/frontend-style.css' );
  44. $this->add_js_variables();
  45. wp_enqueue_script( 'booked-wc-fe-functions' );
  46. endif;
  47. }
  48. public function enqueue_back_end_script() {
  49. wp_register_script( 'booked-wc-admin-functions', $this->plugin_url . '/js/admin-functions.js', array('jquery') );
  50. wp_enqueue_style( 'booked-wc-admin-styles', $this->plugin_url . '/css/admin-style.css' );
  51. $this->add_js_variables();
  52. wp_enqueue_script( 'booked-wc-admin-functions' );
  53. }
  54. }