Templates
3 weeks ago
TranslationEditor
3 weeks ago
Calendar.php
1 year ago
Emails.php
3 weeks ago
Factory.php
3 weeks ago
MulticurrencyHooks.php
3 weeks ago
Prices.php
3 weeks ago
SharedHooks.php
3 weeks ago
Slots.php
3 weeks ago
class-wcml-accommodation-bookings.php
3 weeks ago
class-wcml-bookings.php
3 weeks ago
SharedHooks.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcBookings; |
| 4 | |
| 5 | use WC_Product; |
| 6 | use WCML_Bookings; |
| 7 | |
| 8 | class SharedHooks implements \IWPML_Action { |
| 9 | |
| 10 | private $wpdb; |
| 11 | |
| 12 | public function __construct( \wpdb $wpdb ) { |
| 13 | $this->wpdb = $wpdb; |
| 14 | } |
| 15 | |
| 16 | public function add_hooks() { |
| 17 | add_action( 'init', [ __CLASS__, 'load_assets' ] ); |
| 18 | add_filter( 'wcml_multi_currency_ajax_actions', [ __CLASS__, 'wcml_multi_currency_is_ajax' ] ); |
| 19 | |
| 20 | $this->clear_transient_fields(); |
| 21 | } |
| 22 | |
| 23 | public static function load_assets( $externalProductType = false ) { |
| 24 | global $pagenow; |
| 25 | |
| 26 | $productId = $pagenow == 'post.php' && isset( $_GET['post'] ) ? (int) $_GET['post'] : false; |
| 27 | |
| 28 | if ( $productId && get_post_type( $productId ) === 'product' ) { |
| 29 | $product = wc_get_product( $productId ); |
| 30 | $productType = $product->get_type(); |
| 31 | |
| 32 | if ( ( self::isBooking( $product ) || $productType === $externalProductType ) || $pagenow == 'post-new.php' ) { |
| 33 | wp_register_style( 'wcml-bookings-css', WCML_PLUGIN_URL . '/compatibility/res/css/wcml-bookings.css', [], WCML_VERSION ); |
| 34 | wp_enqueue_style( 'wcml-bookings-css' ); |
| 35 | |
| 36 | wp_register_script( 'wcml-bookings-js', WCML_PLUGIN_URL . '/compatibility/res/js/wcml-bookings.js', [ 'jquery' ], WCML_VERSION, true ); |
| 37 | wp_enqueue_script( 'wcml-bookings-js' ); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | public static function wcml_multi_currency_is_ajax( $actions ) { |
| 43 | $actions[] = 'wc_bookings_calculate_costs'; |
| 44 | |
| 45 | return $actions; |
| 46 | } |
| 47 | |
| 48 | public function clear_transient_fields() { |
| 49 | if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == WCML_Bookings::POST_TYPE && isset( $_GET['page'] ) && $_GET['page'] == 'booking_calendar' ) { |
| 50 | |
| 51 | $this->wpdb->query( |
| 52 | " |
| 53 | DELETE FROM {$this->wpdb->options} |
| 54 | WHERE option_name LIKE '%book_dr_%' |
| 55 | " |
| 56 | ); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | public static function isBooking( $product ) { |
| 61 | if ( ! $product instanceof WC_Product ) { |
| 62 | $product = wc_get_product( $product ); |
| 63 | } |
| 64 | |
| 65 | return $product && $product->get_type() === 'booking'; |
| 66 | } |
| 67 | } |
| 68 |