WooCommerce Easy Booking, by @_Ashanna
Add provided code to functions.php and update Settings.
Calculation option “Use prices modified by other plugins” must be ON.
System option “Suppress other pricing plugins in frontend” must be OFF.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<?php add_filter( 'wdp_save_cart_item_keys', function ( $keys ) { return array_merge( $keys, array( '_booking_price', '_booking_duration', '_ebs_start', '_ebs_end', 'addons' ) ); } ); add_filter( 'wdp_wc_cart_item_before_clear_from_rules_keys', function ( $wc_cart_item, $wc_cart_item_key ) { if ( isset( $wc_cart_item['_booking_price'], $wc_cart_item['wdp_original_price'] ) ) { $wc_cart_item['_booking_price'] = $wc_cart_item['wdp_original_price']; }; return $wc_cart_item; }, 10, 2 ); $replace_price = function ( $price, $product, $_product, $data, $price_type ) { if ( 'price' === $price_type ) { $price = $_product->is_on_sale() ? $_product->get_sale_price() * $data['duration'] : $price; } return $price; }; add_filter( 'easy_booking_one_date_price', $replace_price, 10, 5 ); add_filter( 'easy_booking_two_dates_price', $replace_price, 10, 5 ); add_filter( "wdp_get_product_price", function ( $price, $product, $price_mode, $item_meta ) { if ( $product->is_on_sale( 'edit' ) ) { if ( 'sale_price' === $price_mode ) { $price = $product->get_sale_price( '' ); } elseif ( 'discount_sale' === $price_mode ) { $price = $product->get_sale_price( '' ); } else { $price = $product->get_regular_price( '' ); } } else { $price = $product->get_price( '' ); } if ( isset( $item_meta['_booking_duration'] ) ) { $price *= $item_meta['_booking_duration']; } return $price; }, 10, 4 ); |