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 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / compatibility / WcBookings / class-wcml-accommodation-bookings.php
woocommerce-multilingual / compatibility / WcBookings Last commit date
Templates 4 weeks ago TranslationEditor 4 weeks ago Calendar.php 1 year ago Emails.php 4 weeks ago Factory.php 4 weeks ago MulticurrencyHooks.php 4 weeks ago Prices.php 4 weeks ago SharedHooks.php 4 weeks ago Slots.php 4 weeks ago class-wcml-accommodation-bookings.php 4 weeks ago class-wcml-bookings.php 4 weeks ago
class-wcml-accommodation-bookings.php
183 lines
1 <?php
2
3 use WCML\Compatibility\WcBookings\SharedHooks;
4 use WCML\Compatibility\WcBookings\Prices;
5
6 class WCML_Accommodation_Bookings implements \IWPML_Action {
7
8 private $woocommerce_wpml;
9
10 public function __construct( \woocommerce_wpml $woocommerce_wpml ) {
11 $this->woocommerce_wpml = $woocommerce_wpml;
12 }
13
14 public function add_hooks() {
15 add_action( 'woocommerce_accommodation_bookings_after_booking_base_cost', [ $this, 'wcml_price_field_after_booking_base_cost', ] );
16 add_action( 'woocommerce_accommodation_bookings_after_booking_pricing_override_block_cost', [ $this, 'wcml_price_field_after_booking_pricing_override_block_cost', ], 10, 2 );
17 add_action( 'woocommerce_accommodation_bookings_after_bookings_pricing', [ $this, 'after_bookings_pricing' ] );
18
19 add_action( 'save_post', [ $this, 'save_custom_costs' ], 110, 2 );
20
21 if ( ! is_admin() ) {
22 add_filter( 'get_post_metadata', [ $this, 'product_price_filter' ], 9, 4 );
23 }
24
25 add_action( 'init', [ $this, 'load_assets' ], 100 );
26 }
27
28 public function wcml_price_field_after_booking_base_cost( $post_id ){
29
30 $this->echo_wcml_price_field( $post_id, 'wcml_wc_booking_base_cost' );
31
32 }
33
34 public function wcml_price_field_after_booking_pricing_override_block_cost( $pricing, $post_id ){
35
36 $this->echo_wcml_price_field( $post_id, 'wcml_wc_booking_pricing_override_block_cost', $pricing );
37
38 }
39
40 public function after_bookings_pricing( $post_id ){
41
42 $product_terms = wp_get_post_terms( $post_id, 'product_type', [ "fields" => "names" ] );
43
44 if(
45 in_array( 'accommodation-booking', $product_terms ) &&
46 $this->woocommerce_wpml->products->is_original_product( $post_id )
47 ){
48
49 $custom_costs_status = get_post_meta( $post_id, Prices::CUSTOM_COSTS_STATUS_KEY, true );
50
51 $checked = !$custom_costs_status ? 'checked="checked"' : ' ';
52
53 echo '<div class="wcml_custom_costs">';
54
55 echo '<input type="radio" name="_wcml_custom_costs" id="wcml_custom_costs_auto" value="0" class="wcml_custom_costs_input" '. $checked .' />';
56 echo '<label for="wcml_custom_costs_auto">'. __('Calculate costs in other currencies automatically', 'woocommerce-multilingual') .'</label>';
57
58 $checked = $custom_costs_status == 1 ? 'checked="checked"' : ' ';
59
60 echo '<input type="radio" name="_wcml_custom_costs" value="1" id="wcml_custom_costs_manually" class="wcml_custom_costs_input" '. $checked .' />';
61 echo '<label for="wcml_custom_costs_manually">'. __('Set costs in other currencies manually', 'woocommerce-multilingual') .'</label>';
62
63 wp_nonce_field( 'wcml_save_accommodation_bookings_custom_costs', '_wcml_custom_costs_nonce' );
64
65 echo '</div>';
66 }
67
68 }
69
70 private function echo_wcml_price_field( $post_id, $field, $pricing = false, $check = true, $resource_id = false ){
71
72 if ( ! $check || $this->woocommerce_wpml->products->is_original_product( $post_id ) ) {
73
74 $currencies = $this->woocommerce_wpml->multi_currency->get_currencies();
75
76 echo '<div class="wcml_custom_cost_field" >';
77
78 foreach($currencies as $currency_code => $currency){
79
80 switch( $field ){
81 case 'wcml_wc_booking_base_cost':
82 woocommerce_wp_text_input( [ 'id' => 'wcml_wc_booking_base_cost', 'class'=>'wcml_bookings_custom_price', 'name' => 'wcml_wc_accommodation_booking_base_cost['.$currency_code.']', 'label' => get_woocommerce_currency_symbol($currency_code), 'description' => __( 'This is the cost per block booked. All other costs (for resources and persons) are added to this.', 'woocommerce-bookings' ), 'value' => get_post_meta( $post_id, '_wc_booking_base_cost_'.$currency_code, true ), 'type' => 'number', 'desc_tip' => true, 'custom_attributes' => [
83 'min' => '',
84 'step' => '0.01',
85 ] ] );
86 break;
87
88
89 case 'wcml_wc_booking_pricing_override_block_cost':
90
91 if( isset( $pricing[ 'override_block_'.$currency_code ] ) ){
92 $value = $pricing[ 'override_block_'.$currency_code ];
93 }else{
94 $value = '';
95 }
96
97 echo '<div class="wcml_bookings_range_block" >';
98 echo '<label>'. get_woocommerce_currency_symbol($currency_code) .'</label>';
99 echo '<input type="number" step="0.01" name="wcml_wc_accommodation_booking_pricing_override_block_cost['.$currency_code.']" class="wcml_bookings_custom_price" value="'. $value .'" placeholder="0" />';
100 echo '</div>';
101 break;
102
103 default:
104 break;
105
106 }
107
108 }
109
110 echo '</div>';
111
112 }
113 }
114
115 public function save_custom_costs( $post_id, $post ){
116
117 $nonce = filter_input( INPUT_POST, '_wcml_custom_costs_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
118
119 if( isset( $_POST['_wcml_custom_costs'] ) && isset( $nonce ) && wp_verify_nonce( $nonce, 'wcml_save_accommodation_bookings_custom_costs' ) ){
120
121 update_post_meta( $post_id, Prices::CUSTOM_COSTS_STATUS_KEY, $_POST['_wcml_custom_costs'] );
122
123 if( $_POST['_wcml_custom_costs'] == 1 ){
124
125 $currencies = $this->woocommerce_wpml->multi_currency->get_currencies();
126
127 foreach( $currencies as $code => $currency ){
128
129 $wc_booking_base_cost = $_POST[ 'wcml_wc_accommodation_booking_base_cost' ][ $code ];
130 update_post_meta( $post_id, '_wc_booking_base_cost_'.$code, $wc_booking_base_cost );
131 update_post_meta( $post_id, '_price_'.$code, $wc_booking_base_cost );
132
133 }
134
135 $updated_meta = [];
136 $booking_pricing = get_post_meta( $post_id, '_wc_booking_pricing', true );
137
138 foreach ( maybe_unserialize( $booking_pricing ) as $key => $prices ) {
139
140 $updated_meta[ $key ] = $prices;
141
142 foreach ( $currencies as $code => $currency ) {
143
144 $updated_meta[ $key ][ 'override_block_'.$code ] = $_POST[ 'wcml_wc_accommodation_booking_pricing_override_block_cost' ][ $code ];
145
146 }
147
148 }
149
150 update_post_meta( $post_id, '_wc_booking_pricing', $updated_meta );
151
152 }
153 }
154
155 }
156
157 public function product_price_filter( $value, $object_id, $meta_key, $single ){
158
159 if (
160 '_price' === $meta_key &&
161 'product' === get_post_type( $object_id ) &&
162 ( $currency = $this->woocommerce_wpml->multi_currency->get_client_currency() ) !== wcml_get_woocommerce_currency_option()
163 ) {
164 remove_filter( 'get_post_metadata', [ $this, 'product_price_filter' ], 9 );
165
166 $original_product = $this->woocommerce_wpml->products->get_original_product_id( $object_id );
167
168 if ( get_post_meta( $original_product, Prices::CUSTOM_COSTS_STATUS_KEY ) ) {
169
170 $price = get_post_meta( $object_id, '_price_' . $currency , true );
171 }
172
173 add_filter( 'get_post_metadata', [ $this, 'product_price_filter' ], 9, 4 );
174 }
175
176 return isset( $price) ? $price : $value;
177 }
178
179 public function load_assets() {
180 SharedHooks::load_assets( 'accommodation-booking' );
181 }
182
183 }