Version Description
- Fix: Added priority to checkout fields to avoid undefined index error in Woo 3.5.1
- Fix: Do not remove default Woo order confirmation hooks if feature is disabled
- Fix: Order submit nonce naming fallback
- Improvement: Fee shared tax calculation
- Improvement: REST API boolean data handling
- Improvement: New REST API unit tests
Download this release
Release Info
Developer | vendidero |
Plugin | WooCommerce Germanized |
Version | 2.2.4 |
Comparing to | |
See all releases |
Code changes from version 2.2.3 to 2.2.4
- includes/abstracts/abstract-wc-gzd-product.php +13 -8
- includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data-variable.php +11 -15
- includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data.php +65 -23
- includes/api/class-wc-gzd-rest-products-controller.php +35 -37
- includes/class-wc-gzd-checkout.php +30 -24
- includes/class-wc-gzd-dhl-parcel-shops.php +4 -3
- includes/class-wc-gzd-shipping-rate.php +18 -8
- includes/emails/class-wc-gzd-email-customer-processing-order.php +12 -9
- readme.txt +9 -1
- templates/checkout/order-submit.php +1 -2
- woocommerce-germanized.php +6 -4
includes/abstracts/abstract-wc-gzd-product.php
CHANGED
@@ -25,8 +25,8 @@ class WC_GZD_Product {
|
|
25 |
'unit_price_regular' => '',
|
26 |
'unit_price_sale' => '',
|
27 |
'unit_price_auto' => '',
|
28 |
-
'mini_desc' => '',
|
29 |
'service' => '',
|
|
|
30 |
'gzd_product' => NULL,
|
31 |
);
|
32 |
|
@@ -69,30 +69,31 @@ class WC_GZD_Product {
|
|
69 |
|
70 |
$value = wc_gzd_get_crud_data( $this->child, $key );
|
71 |
|
72 |
-
if ( '' === $value )
|
73 |
$value = $this->gzd_variation_level_meta[ $key ];
|
|
|
74 |
|
75 |
} elseif ( $this->child->is_type( 'variation' ) && in_array( $key, $this->gzd_variation_inherited_meta_data ) ) {
|
76 |
-
|
77 |
$value = wc_gzd_get_crud_data( $this->child, $key ) ? wc_gzd_get_crud_data( $this->child, $key ) : '';
|
78 |
|
79 |
// Handle meta data keys which can be empty at variation level to cause inheritance
|
80 |
if ( ! $value || '' === $value ) {
|
81 |
-
|
82 |
$parent = wc_get_product( wc_gzd_get_crud_data( $this->child, 'parent' ) );
|
|
|
83 |
// Check if parent exists
|
84 |
-
if ( $parent )
|
85 |
$value = wc_gzd_get_crud_data( $parent, $key );
|
|
|
86 |
}
|
87 |
|
88 |
} elseif ( $key == 'delivery_time' ) {
|
89 |
-
|
90 |
$value = $this->get_delivery_time();
|
91 |
-
|
92 |
} else {
|
93 |
|
94 |
-
if ( strpos( '_', $key ) !== true )
|
95 |
$key = '_' . $key;
|
|
|
96 |
|
97 |
$value = wc_gzd_get_crud_data( $this->child, $key );
|
98 |
}
|
@@ -298,6 +299,10 @@ class WC_GZD_Product {
|
|
298 |
return ( $this->unit_base ) ? ( $this->unit_base != apply_filters( 'woocommerce_gzd_unit_base_hide_amount', 1 ) ? '<span class="unit-base">' . $this->unit_base . '</span>' . apply_filters( 'wc_gzd_unit_price_base_seperator', ' ' ) : '' ) . '<span class="unit">' . $this->get_unit() . '</span>' : '';
|
299 |
}
|
300 |
|
|
|
|
|
|
|
|
|
301 |
public function get_unit_term() {
|
302 |
$unit = $this->unit;
|
303 |
|
25 |
'unit_price_regular' => '',
|
26 |
'unit_price_sale' => '',
|
27 |
'unit_price_auto' => '',
|
|
|
28 |
'service' => '',
|
29 |
+
'mini_desc' => '',
|
30 |
'gzd_product' => NULL,
|
31 |
);
|
32 |
|
69 |
|
70 |
$value = wc_gzd_get_crud_data( $this->child, $key );
|
71 |
|
72 |
+
if ( '' === $value ) {
|
73 |
$value = $this->gzd_variation_level_meta[ $key ];
|
74 |
+
}
|
75 |
|
76 |
} elseif ( $this->child->is_type( 'variation' ) && in_array( $key, $this->gzd_variation_inherited_meta_data ) ) {
|
77 |
+
|
78 |
$value = wc_gzd_get_crud_data( $this->child, $key ) ? wc_gzd_get_crud_data( $this->child, $key ) : '';
|
79 |
|
80 |
// Handle meta data keys which can be empty at variation level to cause inheritance
|
81 |
if ( ! $value || '' === $value ) {
|
|
|
82 |
$parent = wc_get_product( wc_gzd_get_crud_data( $this->child, 'parent' ) );
|
83 |
+
|
84 |
// Check if parent exists
|
85 |
+
if ( $parent ) {
|
86 |
$value = wc_gzd_get_crud_data( $parent, $key );
|
87 |
+
}
|
88 |
}
|
89 |
|
90 |
} elseif ( $key == 'delivery_time' ) {
|
|
|
91 |
$value = $this->get_delivery_time();
|
|
|
92 |
} else {
|
93 |
|
94 |
+
if ( strpos( '_', $key ) !== true ) {
|
95 |
$key = '_' . $key;
|
96 |
+
}
|
97 |
|
98 |
$value = wc_gzd_get_crud_data( $this->child, $key );
|
99 |
}
|
299 |
return ( $this->unit_base ) ? ( $this->unit_base != apply_filters( 'woocommerce_gzd_unit_base_hide_amount', 1 ) ? '<span class="unit-base">' . $this->unit_base . '</span>' . apply_filters( 'wc_gzd_unit_price_base_seperator', ' ' ) : '' ) . '<span class="unit">' . $this->get_unit() . '</span>' : '';
|
300 |
}
|
301 |
|
302 |
+
public function get_unit_base_raw() {
|
303 |
+
return $this->unit_base;
|
304 |
+
}
|
305 |
+
|
306 |
public function get_unit_term() {
|
307 |
$unit = $this->unit;
|
308 |
|
includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data-variable.php
CHANGED
@@ -28,7 +28,6 @@ class WC_Germanized_Meta_Box_Product_Data_Variable {
|
|
28 |
}
|
29 |
|
30 |
private function __construct() {
|
31 |
-
|
32 |
if ( is_admin() ) {
|
33 |
add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'output' ), 20, 3 );
|
34 |
add_action( 'woocommerce_save_product_variation', array( __CLASS__, 'save' ) , 0, 2 );
|
@@ -177,32 +176,29 @@ class WC_Germanized_Meta_Box_Product_Data_Variable {
|
|
177 |
);
|
178 |
|
179 |
foreach ( $data as $k => $v ) {
|
180 |
-
|
181 |
$data_k = 'variable' . ( substr( $k, 0, 1) === '_' ? '' : '_' ) . $k;
|
182 |
$data[ $k ] = ( isset( $_POST[ $data_k ][$i] ) ? $_POST[ $data_k ][$i] : null );
|
183 |
-
|
184 |
}
|
185 |
|
186 |
-
$product
|
187 |
$product_parent = wc_get_product( wc_gzd_get_crud_data( $product, 'parent' ) );
|
188 |
|
189 |
// Check if parent has unit_base + unit otherwise ignore data
|
190 |
-
if ( empty( $data[
|
191 |
-
|
192 |
-
$data[
|
193 |
-
$data[
|
194 |
-
$data[ '_unit_price_sale' ] = '';
|
195 |
}
|
196 |
|
197 |
// If parent has no unit, delete unit_product as well
|
198 |
-
if ( empty( $data[
|
199 |
-
$data[
|
200 |
}
|
201 |
|
202 |
-
$data[
|
203 |
-
$data[
|
204 |
-
$data[
|
205 |
-
$data[
|
206 |
|
207 |
$product = WC_Germanized_Meta_Box_Product_Data::save_product_data( $product, $data, true );
|
208 |
}
|
28 |
}
|
29 |
|
30 |
private function __construct() {
|
|
|
31 |
if ( is_admin() ) {
|
32 |
add_action( 'woocommerce_product_after_variable_attributes', array( __CLASS__, 'output' ), 20, 3 );
|
33 |
add_action( 'woocommerce_save_product_variation', array( __CLASS__, 'save' ) , 0, 2 );
|
176 |
);
|
177 |
|
178 |
foreach ( $data as $k => $v ) {
|
|
|
179 |
$data_k = 'variable' . ( substr( $k, 0, 1) === '_' ? '' : '_' ) . $k;
|
180 |
$data[ $k ] = ( isset( $_POST[ $data_k ][$i] ) ? $_POST[ $data_k ][$i] : null );
|
|
|
181 |
}
|
182 |
|
183 |
+
$product = wc_get_product( $variation_id );
|
184 |
$product_parent = wc_get_product( wc_gzd_get_crud_data( $product, 'parent' ) );
|
185 |
|
186 |
// Check if parent has unit_base + unit otherwise ignore data
|
187 |
+
if ( empty( $data['_parent_unit'] ) || empty( $data['_parent_unit_base'] ) ) {
|
188 |
+
$data['_unit_price_auto'] = '';
|
189 |
+
$data['_unit_price_regular'] = '';
|
190 |
+
$data['_unit_price_sale'] = '';
|
|
|
191 |
}
|
192 |
|
193 |
// If parent has no unit, delete unit_product as well
|
194 |
+
if ( empty( $data['_parent_unit'] ) ) {
|
195 |
+
$data['_unit_product'] = '';
|
196 |
}
|
197 |
|
198 |
+
$data['product-type'] = $product_parent->get_type();
|
199 |
+
$data['_sale_price_dates_from'] = $_POST['variable_sale_price_dates_from'][$i];
|
200 |
+
$data['_sale_price_dates_to'] = $_POST['variable_sale_price_dates_to'][$i];
|
201 |
+
$data['_sale_price'] = $_POST['variable_sale_price'][$i];
|
202 |
|
203 |
$product = WC_Germanized_Meta_Box_Product_Data::save_product_data( $product, $data, true );
|
204 |
}
|
includes/admin/meta-boxes/class-wc-gzd-meta-box-product-data.php
CHANGED
@@ -276,12 +276,37 @@ class WC_Germanized_Meta_Box_Product_Data {
|
|
276 |
return $product;
|
277 |
}
|
278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
public static function save_unit_price( $product, $data, $is_variation = false ) {
|
280 |
|
281 |
$data = wp_parse_args( $data, array(
|
282 |
-
'save'
|
|
|
283 |
) );
|
284 |
|
|
|
|
|
|
|
|
|
285 |
if ( is_numeric( $product ) ) {
|
286 |
$product = wc_get_product( $product );
|
287 |
}
|
@@ -289,12 +314,10 @@ class WC_Germanized_Meta_Box_Product_Data {
|
|
289 |
$product_type = ( ! isset( $data['product-type'] ) || empty( $data['product-type'] ) ) ? 'simple' : sanitize_title( stripslashes( $data['product-type'] ) );
|
290 |
|
291 |
if ( isset( $data['_unit'] ) ) {
|
292 |
-
|
293 |
if ( empty( $data['_unit'] ) || in_array( $data['_unit'], array( 'none', '-1' ) ) )
|
294 |
$product = wc_gzd_unset_crud_meta_data( $product, '_unit' );
|
295 |
else
|
296 |
$product = wc_gzd_set_crud_meta_data( $product, '_unit', sanitize_text_field( $data['_unit'] ) );
|
297 |
-
|
298 |
}
|
299 |
|
300 |
if ( isset( $data['_unit_base'] ) ) {
|
@@ -313,7 +336,6 @@ class WC_Germanized_Meta_Box_Product_Data {
|
|
313 |
}
|
314 |
|
315 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
316 |
-
|
317 |
// Unset unit price sale if no product sale price has been defined
|
318 |
if ( ! isset( $data['_sale_price'] ) || $data['_sale_price'] === '' )
|
319 |
$data['_unit_price_sale'] = '';
|
@@ -331,24 +353,34 @@ class WC_Germanized_Meta_Box_Product_Data {
|
|
331 |
|
332 |
} else {
|
333 |
|
334 |
-
$date_from
|
335 |
-
$date_to
|
|
|
336 |
|
337 |
// Update price if on sale
|
338 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
352 |
}
|
353 |
}
|
354 |
|
@@ -360,17 +392,27 @@ class WC_Germanized_Meta_Box_Product_Data {
|
|
360 |
}
|
361 |
|
362 |
public static function save_product_data( $product, $data, $is_variation = false ) {
|
363 |
-
|
364 |
if ( is_numeric( $product ) )
|
365 |
$product = wc_get_product( $product );
|
366 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
$data = apply_filters( 'woocommerce_gzd_product_saveable_data', $data, $product );
|
|
|
368 |
$data = wp_parse_args( $data, array(
|
369 |
-
'save'
|
|
|
370 |
) );
|
371 |
|
372 |
-
$unit_data
|
373 |
-
$unit_data[
|
|
|
374 |
$product = self::save_unit_price( $product, $unit_data, $is_variation );
|
375 |
|
376 |
$product_type = ( ! isset( $data['product-type'] ) || empty( $data['product-type'] ) ) ? 'simple' : sanitize_title( stripslashes( $data['product-type'] ) );
|
276 |
return $product;
|
277 |
}
|
278 |
|
279 |
+
public static function get_default_product_data( $product ) {
|
280 |
+
$fields = array(
|
281 |
+
'product-type' => $product->get_type(),
|
282 |
+
'_sale_price_dates_from' => '',
|
283 |
+
'_sale_price_dates_to' => '',
|
284 |
+
'_is_on_sale' => $product->is_on_sale(),
|
285 |
+
'_sale_price' => wc_gzd_get_crud_data( $product, 'sale_price' ),
|
286 |
+
);
|
287 |
+
|
288 |
+
if ( is_a( $fields['_sale_price_dates_from'], 'WC_DateTime' ) ) {
|
289 |
+
$fields['_sale_price_dates_from'] = $fields['_sale_price_dates_from']->date_i18n();
|
290 |
+
}
|
291 |
+
|
292 |
+
if ( is_a( $fields['_sale_price_dates_to'], 'WC_DateTime' ) ) {
|
293 |
+
$fields['_sale_price_dates_to'] = $fields['_sale_price_dates_to']->date_i18n();
|
294 |
+
}
|
295 |
+
|
296 |
+
return $fields;
|
297 |
+
}
|
298 |
+
|
299 |
public static function save_unit_price( $product, $data, $is_variation = false ) {
|
300 |
|
301 |
$data = wp_parse_args( $data, array(
|
302 |
+
'save' => true,
|
303 |
+
'is_rest' => false,
|
304 |
) );
|
305 |
|
306 |
+
if ( $data['is_rest'] ) {
|
307 |
+
$data = array_replace_recursive( static::get_default_product_data( $product ), $data );
|
308 |
+
}
|
309 |
+
|
310 |
if ( is_numeric( $product ) ) {
|
311 |
$product = wc_get_product( $product );
|
312 |
}
|
314 |
$product_type = ( ! isset( $data['product-type'] ) || empty( $data['product-type'] ) ) ? 'simple' : sanitize_title( stripslashes( $data['product-type'] ) );
|
315 |
|
316 |
if ( isset( $data['_unit'] ) ) {
|
|
|
317 |
if ( empty( $data['_unit'] ) || in_array( $data['_unit'], array( 'none', '-1' ) ) )
|
318 |
$product = wc_gzd_unset_crud_meta_data( $product, '_unit' );
|
319 |
else
|
320 |
$product = wc_gzd_set_crud_meta_data( $product, '_unit', sanitize_text_field( $data['_unit'] ) );
|
|
|
321 |
}
|
322 |
|
323 |
if ( isset( $data['_unit_base'] ) ) {
|
336 |
}
|
337 |
|
338 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
|
|
339 |
// Unset unit price sale if no product sale price has been defined
|
340 |
if ( ! isset( $data['_sale_price'] ) || $data['_sale_price'] === '' )
|
341 |
$data['_unit_price_sale'] = '';
|
353 |
|
354 |
} else {
|
355 |
|
356 |
+
$date_from = isset( $data['_sale_price_dates_from'] ) ? wc_clean( $data['_sale_price_dates_from'] ) : '';
|
357 |
+
$date_to = isset( $data['_sale_price_dates_to'] ) ? wc_clean( $data['_sale_price_dates_to'] ) : '';
|
358 |
+
$is_on_sale = isset( $data['_is_on_sale'] ) ? $data['_is_on_sale'] : null;
|
359 |
|
360 |
// Update price if on sale
|
361 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
362 |
+
|
363 |
+
if ( ! is_null( $is_on_sale ) ) {
|
364 |
+
if ( $is_on_sale ) {
|
365 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', wc_format_decimal( $data['_unit_price_sale'] ) );
|
366 |
+
} else {
|
367 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', ( $data['_unit_price_regular'] === '' ) ? '' : wc_format_decimal( $data['_unit_price_regular'] ) );
|
368 |
+
}
|
369 |
+
} else {
|
370 |
+
if ( '' !== $data['_unit_price_sale'] && '' == $date_to && '' == $date_from ) {
|
371 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', wc_format_decimal( $data['_unit_price_sale'] ) );
|
372 |
+
} else {
|
373 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', ( $data['_unit_price_regular'] === '' ) ? '' : wc_format_decimal( $data['_unit_price_regular'] ) );
|
374 |
+
}
|
375 |
+
|
376 |
+
if ( '' !== $data['_unit_price_sale'] && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
377 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', wc_format_decimal( $data['_unit_price_sale'] ) );
|
378 |
+
}
|
379 |
+
|
380 |
+
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
|
381 |
+
$product = wc_gzd_set_crud_meta_data( $product, '_unit_price', ( $data['_unit_price_regular'] === '' ) ? '' : wc_format_decimal( $data['_unit_price_regular'] ) );
|
382 |
+
}
|
383 |
+
}
|
384 |
}
|
385 |
}
|
386 |
|
392 |
}
|
393 |
|
394 |
public static function save_product_data( $product, $data, $is_variation = false ) {
|
|
|
395 |
if ( is_numeric( $product ) )
|
396 |
$product = wc_get_product( $product );
|
397 |
|
398 |
+
$data = wp_parse_args( $data, array(
|
399 |
+
'is_rest' => false,
|
400 |
+
) );
|
401 |
+
|
402 |
+
if ( $data['is_rest'] ) {
|
403 |
+
$data = array_replace_recursive( static::get_default_product_data( $product ), $data );
|
404 |
+
}
|
405 |
+
|
406 |
$data = apply_filters( 'woocommerce_gzd_product_saveable_data', $data, $product );
|
407 |
+
|
408 |
$data = wp_parse_args( $data, array(
|
409 |
+
'save' => true,
|
410 |
+
'is_rest' => false,
|
411 |
) );
|
412 |
|
413 |
+
$unit_data = $data;
|
414 |
+
$unit_data['save'] = false;
|
415 |
+
|
416 |
$product = self::save_unit_price( $product, $unit_data, $is_variation );
|
417 |
|
418 |
$product_type = ( ! isset( $data['product-type'] ) || empty( $data['product-type'] ) ) ? 'simple' : sanitize_title( stripslashes( $data['product-type'] ) );
|
includes/api/class-wc-gzd-rest-products-controller.php
CHANGED
@@ -7,7 +7,6 @@
|
|
7 |
class WC_GZD_REST_Products_Controller {
|
8 |
|
9 |
public function __construct() {
|
10 |
-
|
11 |
// v3
|
12 |
if ( wc_gzd_get_dependencies()->woocommerce_version_supports_crud() ) {
|
13 |
add_filter( 'woocommerce_rest_prepare_product_object', array( $this, 'prepare' ), 10, 3 );
|
@@ -335,14 +334,13 @@ class WC_GZD_REST_Products_Controller {
|
|
335 |
}
|
336 |
|
337 |
public function prepare( $response, $post, $request ) {
|
338 |
-
|
339 |
$product = wc_get_product( $post );
|
340 |
|
341 |
// Add variations to variable products.
|
342 |
if ( $product->is_type( 'variable' ) && $product->has_child() ) {
|
343 |
|
344 |
$data = $response->data;
|
345 |
-
$data[
|
346 |
$response->set_data( $data );
|
347 |
|
348 |
}
|
@@ -354,14 +352,12 @@ class WC_GZD_REST_Products_Controller {
|
|
354 |
}
|
355 |
|
356 |
public function insert_update_v3( $product, $request, $inserted ) {
|
357 |
-
|
358 |
$product = $this->save_update_product_data( $request, $product );
|
359 |
|
360 |
return $product;
|
361 |
}
|
362 |
|
363 |
public function insert_update( $post, $request, $inserted ) {
|
364 |
-
|
365 |
$product = wc_get_product( $post );
|
366 |
$product = $this->save_update_product_data( $request, $product );
|
367 |
|
@@ -369,7 +365,6 @@ class WC_GZD_REST_Products_Controller {
|
|
369 |
}
|
370 |
|
371 |
public function save_variation( $variation_id, $menu_order, $request ) {
|
372 |
-
|
373 |
$product = wc_get_product( $variation_id );
|
374 |
$product = $this->save_update_product_data( $request, $product );
|
375 |
|
@@ -379,9 +374,9 @@ class WC_GZD_REST_Products_Controller {
|
|
379 |
public function get_product_saveable_data( $request, $product ) {
|
380 |
|
381 |
$data_saveable = WC_Germanized_Meta_Box_Product_Data::get_fields();
|
382 |
-
$data
|
383 |
|
384 |
-
$data[
|
385 |
|
386 |
// Delivery time
|
387 |
$current = get_the_terms( wc_gzd_get_crud_data( $product, 'id' ), 'product_delivery_time' );
|
@@ -395,13 +390,12 @@ class WC_GZD_REST_Products_Controller {
|
|
395 |
|
396 |
// Price Labels + Unit
|
397 |
$meta_data = array(
|
398 |
-
'sale_price_label'
|
399 |
'sale_price_regular_label' => WC_germanized()->price_labels,
|
400 |
-
'unit'
|
401 |
);
|
402 |
|
403 |
foreach ( $meta_data as $meta => $taxonomy_obj ) {
|
404 |
-
|
405 |
$current = wc_gzd_get_crud_data( $product, $meta );
|
406 |
$term_data = $this->get_term_data( isset( $request[ $meta ] ) ? $request[ $meta ] : false, $current );
|
407 |
$data[ '_' . $meta ] = '';
|
@@ -415,23 +409,28 @@ class WC_GZD_REST_Products_Controller {
|
|
415 |
}
|
416 |
}
|
417 |
|
|
|
|
|
|
|
418 |
if ( isset( $request['unit_price'] ) && is_array( $request['unit_price'] ) ) {
|
419 |
|
420 |
foreach ( $request['unit_price'] as $key => $val ) {
|
421 |
-
|
422 |
-
|
423 |
-
$data[ '_unit_' . $key ] = sanitize_text_field( $val );
|
424 |
}
|
425 |
}
|
426 |
|
427 |
-
if ( isset( $data[
|
428 |
-
$data['_unit_price_auto']
|
429 |
-
|
430 |
-
unset( $data['_unit_price_auto'] );
|
431 |
} else {
|
432 |
$data['_unit_price_auto'] = wc_gzd_get_crud_data( $product, '_unit_price_auto' );
|
433 |
}
|
434 |
|
|
|
|
|
|
|
|
|
435 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
436 |
$data['_sale_price'] = wc_gzd_get_crud_data( $product, 'sale_price' );
|
437 |
}
|
@@ -442,7 +441,6 @@ class WC_GZD_REST_Products_Controller {
|
|
442 |
}
|
443 |
|
444 |
foreach( array( 'free_shipping', 'service', 'differential_taxation' ) as $bool_meta ) {
|
445 |
-
|
446 |
if ( isset( $request[$bool_meta] ) ) {
|
447 |
if ( ! empty( $request[$bool_meta] ) )
|
448 |
$data[ "_{$bool_meta}" ] = true;
|
@@ -481,11 +479,11 @@ class WC_GZD_REST_Products_Controller {
|
|
481 |
}
|
482 |
|
483 |
public function save_update_product_data( $request, $product ) {
|
|
|
|
|
|
|
484 |
|
485 |
-
$
|
486 |
-
$data['save'] = false;
|
487 |
-
|
488 |
-
$product = WC_Germanized_Meta_Box_Product_Data::save_product_data( $product, $data );
|
489 |
|
490 |
return $product;
|
491 |
}
|
@@ -493,8 +491,8 @@ class WC_GZD_REST_Products_Controller {
|
|
493 |
private function set_product_variation_fields( $variations, $product ) {
|
494 |
|
495 |
foreach( $variations as $key => $variation ) {
|
496 |
-
if( isset($variation[
|
497 |
-
$variations[ $key ] = array_merge( $variation, $this->get_product_data( wc_get_product( $variation[
|
498 |
}
|
499 |
}
|
500 |
|
@@ -508,12 +506,12 @@ class WC_GZD_REST_Products_Controller {
|
|
508 |
$data = array();
|
509 |
|
510 |
if ( ! $product->is_type( 'variation' ) ) {
|
511 |
-
$data[
|
512 |
}
|
513 |
|
514 |
// Unit Price
|
515 |
-
$data[
|
516 |
-
'base' => $product->
|
517 |
'product' => $product->get_unit_products(),
|
518 |
'price_auto' => $product->is_unit_price_calculated_automatically(),
|
519 |
'price' => $product->get_unit_price(),
|
@@ -523,27 +521,27 @@ class WC_GZD_REST_Products_Controller {
|
|
523 |
);
|
524 |
|
525 |
// Cart Mini Description
|
526 |
-
$data[
|
527 |
|
528 |
// Sale Labels
|
529 |
-
$data[
|
530 |
-
$data[
|
531 |
|
532 |
// Delivery Time
|
533 |
-
$data[
|
534 |
|
535 |
-
if ( ! empty( $data[
|
536 |
-
$data[
|
537 |
}
|
538 |
|
539 |
// Shipping costs hidden?
|
540 |
-
$data[
|
541 |
|
542 |
// Shipping costs hidden?
|
543 |
-
$data[
|
544 |
|
545 |
// Shipping costs hidden?
|
546 |
-
$data[
|
547 |
|
548 |
return $data;
|
549 |
}
|
7 |
class WC_GZD_REST_Products_Controller {
|
8 |
|
9 |
public function __construct() {
|
|
|
10 |
// v3
|
11 |
if ( wc_gzd_get_dependencies()->woocommerce_version_supports_crud() ) {
|
12 |
add_filter( 'woocommerce_rest_prepare_product_object', array( $this, 'prepare' ), 10, 3 );
|
334 |
}
|
335 |
|
336 |
public function prepare( $response, $post, $request ) {
|
|
|
337 |
$product = wc_get_product( $post );
|
338 |
|
339 |
// Add variations to variable products.
|
340 |
if ( $product->is_type( 'variable' ) && $product->has_child() ) {
|
341 |
|
342 |
$data = $response->data;
|
343 |
+
$data['variations'] = $this->set_product_variation_fields( $response->data[ 'variations' ], $product );
|
344 |
$response->set_data( $data );
|
345 |
|
346 |
}
|
352 |
}
|
353 |
|
354 |
public function insert_update_v3( $product, $request, $inserted ) {
|
|
|
355 |
$product = $this->save_update_product_data( $request, $product );
|
356 |
|
357 |
return $product;
|
358 |
}
|
359 |
|
360 |
public function insert_update( $post, $request, $inserted ) {
|
|
|
361 |
$product = wc_get_product( $post );
|
362 |
$product = $this->save_update_product_data( $request, $product );
|
363 |
|
365 |
}
|
366 |
|
367 |
public function save_variation( $variation_id, $menu_order, $request ) {
|
|
|
368 |
$product = wc_get_product( $variation_id );
|
369 |
$product = $this->save_update_product_data( $request, $product );
|
370 |
|
374 |
public function get_product_saveable_data( $request, $product ) {
|
375 |
|
376 |
$data_saveable = WC_Germanized_Meta_Box_Product_Data::get_fields();
|
377 |
+
$data = array();
|
378 |
|
379 |
+
$data['product-type'] = $product->get_type();
|
380 |
|
381 |
// Delivery time
|
382 |
$current = get_the_terms( wc_gzd_get_crud_data( $product, 'id' ), 'product_delivery_time' );
|
390 |
|
391 |
// Price Labels + Unit
|
392 |
$meta_data = array(
|
393 |
+
'sale_price_label' => WC_germanized()->price_labels,
|
394 |
'sale_price_regular_label' => WC_germanized()->price_labels,
|
395 |
+
'unit' => WC_germanized()->units,
|
396 |
);
|
397 |
|
398 |
foreach ( $meta_data as $meta => $taxonomy_obj ) {
|
|
|
399 |
$current = wc_gzd_get_crud_data( $product, $meta );
|
400 |
$term_data = $this->get_term_data( isset( $request[ $meta ] ) ? $request[ $meta ] : false, $current );
|
401 |
$data[ '_' . $meta ] = '';
|
409 |
}
|
410 |
}
|
411 |
|
412 |
+
// Set Unit Price Checkbox to current product value
|
413 |
+
$data['_unit_price_auto'] = wc_gzd_get_crud_data( $product, '_unit_price_auto' );
|
414 |
+
|
415 |
if ( isset( $request['unit_price'] ) && is_array( $request['unit_price'] ) ) {
|
416 |
|
417 |
foreach ( $request['unit_price'] as $key => $val ) {
|
418 |
+
if ( isset( $data_saveable['_unit_' . $key] ) ) {
|
419 |
+
$data['_unit_' . $key] = sanitize_text_field( $val );
|
|
|
420 |
}
|
421 |
}
|
422 |
|
423 |
+
if ( isset( $data['_unit_price_auto'] ) ) {
|
424 |
+
if ( ! empty( $data['_unit_price_auto'] ) )
|
425 |
+
$data['_unit_price_auto'] = true;
|
|
|
426 |
} else {
|
427 |
$data['_unit_price_auto'] = wc_gzd_get_crud_data( $product, '_unit_price_auto' );
|
428 |
}
|
429 |
|
430 |
+
// Do only add boolean values if is set so saving works (checkbox-style).
|
431 |
+
if ( empty( $data['_unit_price_auto'] ) || ! $data['_unit_price_auto'] )
|
432 |
+
unset( $data['_unit_price_auto'] );
|
433 |
+
|
434 |
if ( isset( $data['_unit_price_sale'] ) ) {
|
435 |
$data['_sale_price'] = wc_gzd_get_crud_data( $product, 'sale_price' );
|
436 |
}
|
441 |
}
|
442 |
|
443 |
foreach( array( 'free_shipping', 'service', 'differential_taxation' ) as $bool_meta ) {
|
|
|
444 |
if ( isset( $request[$bool_meta] ) ) {
|
445 |
if ( ! empty( $request[$bool_meta] ) )
|
446 |
$data[ "_{$bool_meta}" ] = true;
|
479 |
}
|
480 |
|
481 |
public function save_update_product_data( $request, $product ) {
|
482 |
+
$data = $this->get_product_saveable_data( $request, $product );
|
483 |
+
$data['is_rest'] = true;
|
484 |
+
$data['save'] = false;
|
485 |
|
486 |
+
$product = WC_Germanized_Meta_Box_Product_Data::save_product_data( $product, $data );
|
|
|
|
|
|
|
487 |
|
488 |
return $product;
|
489 |
}
|
491 |
private function set_product_variation_fields( $variations, $product ) {
|
492 |
|
493 |
foreach( $variations as $key => $variation ) {
|
494 |
+
if( isset( $variation['id'] ) ) {
|
495 |
+
$variations[ $key ] = array_merge( $variation, $this->get_product_data( wc_get_product( $variation['id'] ) ) );
|
496 |
}
|
497 |
}
|
498 |
|
506 |
$data = array();
|
507 |
|
508 |
if ( ! $product->is_type( 'variation' ) ) {
|
509 |
+
$data['unit'] = $this->prepare_term( WC_germanized()->units->get_term_object( wc_gzd_get_crud_data( $product, 'unit' ) ) );
|
510 |
}
|
511 |
|
512 |
// Unit Price
|
513 |
+
$data['unit_price'] = array(
|
514 |
+
'base' => $product->get_unit_base_raw(),
|
515 |
'product' => $product->get_unit_products(),
|
516 |
'price_auto' => $product->is_unit_price_calculated_automatically(),
|
517 |
'price' => $product->get_unit_price(),
|
521 |
);
|
522 |
|
523 |
// Cart Mini Description
|
524 |
+
$data['mini_desc'] = $product->get_mini_desc() ? $product->get_mini_desc() : '';
|
525 |
|
526 |
// Sale Labels
|
527 |
+
$data['sale_price_label'] = $this->prepare_term( WC_germanized()->price_labels->get_term_object( $product->get_sale_price_label() ) );
|
528 |
+
$data['sale_price_regular_label'] = $this->prepare_term( WC_germanized()->price_labels->get_term_object( $product->get_sale_price_regular_label() ) );
|
529 |
|
530 |
// Delivery Time
|
531 |
+
$data['delivery_time'] = $this->prepare_term( $product->get_delivery_time_term() );
|
532 |
|
533 |
+
if ( ! empty( $data['delivery_time'] ) ) {
|
534 |
+
$data['delivery_time']['html'] = $product->get_delivery_time_html();
|
535 |
}
|
536 |
|
537 |
// Shipping costs hidden?
|
538 |
+
$data['free_shipping'] = $product->has_free_shipping();
|
539 |
|
540 |
// Shipping costs hidden?
|
541 |
+
$data['service'] = $product->is_service();
|
542 |
|
543 |
// Shipping costs hidden?
|
544 |
+
$data['differential_taxation'] = $product->is_differential_taxed();
|
545 |
|
546 |
return $data;
|
547 |
}
|
includes/class-wc-gzd-checkout.php
CHANGED
@@ -350,8 +350,8 @@ class WC_GZD_Checkout {
|
|
350 |
|
351 |
if ( $search && isset( $matches[1] ) ) {
|
352 |
$order_id = absint( $matches[1] );
|
353 |
-
$order
|
354 |
-
$return
|
355 |
}
|
356 |
|
357 |
return $return;
|
@@ -359,35 +359,33 @@ class WC_GZD_Checkout {
|
|
359 |
|
360 |
public function init_fields() {
|
361 |
if ( get_option( 'woocommerce_gzd_checkout_address_field' ) == 'yes' ) {
|
362 |
-
|
363 |
-
$this->custom_fields[ 'title' ] = array(
|
364 |
'type' => 'select',
|
365 |
'required' => false,
|
366 |
'label' => __( 'Title', 'woocommerce-germanized' ),
|
367 |
'options' => apply_filters( 'woocommerce_gzd_title_options', array( 1 => __( 'Mr.', 'woocommerce-germanized' ), 2 => __( 'Ms.', 'woocommerce-germanized' ) ) ),
|
368 |
'before' => 'first_name',
|
369 |
'group' => array( 'billing', 'shipping' ),
|
|
|
370 |
);
|
371 |
|
372 |
-
$this->custom_fields_admin[
|
373 |
'before' => 'first_name',
|
374 |
'type' => 'select',
|
375 |
'options' => apply_filters( 'woocommerce_gzd_title_options', array( 1 => __( 'Mr.', 'woocommerce-germanized' ), 2 => __( 'Ms.', 'woocommerce-germanized' ) ) ),
|
376 |
'label' => __( 'Title', 'woocommerce-germanized' ),
|
377 |
'show' => false,
|
|
|
378 |
);
|
379 |
-
|
380 |
}
|
381 |
|
382 |
if ( get_option( 'woocommerce_gzd_checkout_phone_required' ) == 'no' ) {
|
383 |
-
|
384 |
-
$this->custom_fields[ 'phone' ] = array(
|
385 |
'before' => '',
|
386 |
'override' => true,
|
387 |
'required' => false,
|
388 |
'group' => array( 'billing' )
|
389 |
);
|
390 |
-
|
391 |
}
|
392 |
|
393 |
$this->custom_fields_admin = apply_filters( 'woocommerce_gzd_custom_checkout_admin_fields', $this->custom_fields_admin, $this );
|
@@ -475,8 +473,8 @@ class WC_GZD_Checkout {
|
|
475 |
}
|
476 |
|
477 |
$fee->tax_data = $fee_taxes;
|
478 |
-
$fee->tax = $fee_tax_total;
|
479 |
-
$fee->amount = $fee->amount - $fee->tax;
|
480 |
$fee->total = $fee->amount;
|
481 |
|
482 |
$new_fees[ $key ] = $fee;
|
@@ -486,6 +484,10 @@ class WC_GZD_Checkout {
|
|
486 |
$cart->fees_api()->set_fees( $new_fees );
|
487 |
$cart->set_fee_tax( array_sum( $fee_tax_data ) );
|
488 |
$cart->set_fee_taxes( $fee_tax_data );
|
|
|
|
|
|
|
|
|
489 |
}
|
490 |
}
|
491 |
|
@@ -524,6 +526,7 @@ class WC_GZD_Checkout {
|
|
524 |
// Calculate tax class share
|
525 |
if ( ! empty( $tax_shares ) ) {
|
526 |
$fee_taxes = array();
|
|
|
527 |
foreach ( $tax_shares as $rate => $class ) {
|
528 |
$tax_rates = WC_Tax::get_rates( $rate );
|
529 |
$tax_shares[ $rate ]['fee_tax_share'] = $fee->amount * $class['share'];
|
@@ -531,16 +534,19 @@ class WC_GZD_Checkout {
|
|
531 |
|
532 |
$fee_taxes += $tax_shares[ $rate ]['fee_tax'];
|
533 |
}
|
|
|
534 |
foreach ( $tax_shares as $rate => $class ) {
|
535 |
$cart->fees[ $key ]->tax_data = $cart->fees[ $key ]->tax_data + $class['fee_tax'];
|
536 |
}
|
|
|
537 |
// Add fee taxes to cart taxes
|
538 |
foreach ( array_keys( $cart->taxes + $fee_taxes ) as $sub ) {
|
539 |
$cart->taxes[ $sub ] = ( isset( $fee_taxes[ $sub ] ) ? $fee_taxes[ $sub ] : 0 ) + ( isset( $cart->taxes[ $sub ] ) ? $cart->taxes[ $sub ] : 0 );
|
540 |
}
|
|
|
541 |
// Update fee
|
542 |
-
$cart->fees[ $key ]->tax
|
543 |
-
$cart->fees[ $key ]->amount = $cart->fees[ $key ]->amount - $cart->fees[ $key ]->tax;
|
544 |
}
|
545 |
}
|
546 |
}
|
@@ -618,7 +624,7 @@ class WC_GZD_Checkout {
|
|
618 |
return $fields;
|
619 |
|
620 |
if ( wc_gzd_get_crud_data( $order, 'billing_title' ) )
|
621 |
-
$fields[
|
622 |
|
623 |
return $fields;
|
624 |
}
|
@@ -629,7 +635,7 @@ class WC_GZD_Checkout {
|
|
629 |
return $fields;
|
630 |
|
631 |
if ( wc_gzd_get_crud_data( $order, 'shipping_title' ) )
|
632 |
-
$fields[
|
633 |
|
634 |
return $fields;
|
635 |
}
|
@@ -652,11 +658,11 @@ class WC_GZD_Checkout {
|
|
652 |
}
|
653 |
|
654 |
public function set_formatted_address( $placeholder, $args ) {
|
655 |
-
if ( isset( $args[
|
656 |
-
$placeholder[
|
657 |
-
$placeholder[
|
658 |
-
$placeholder[
|
659 |
-
$placeholder[
|
660 |
}
|
661 |
return $placeholder;
|
662 |
}
|
@@ -710,13 +716,13 @@ class WC_GZD_Checkout {
|
|
710 |
|
711 |
$new = array();
|
712 |
|
713 |
-
if ( isset( $custom_field[
|
714 |
continue;
|
715 |
|
716 |
if ( ! empty( $fields ) ) {
|
717 |
|
718 |
foreach ( $fields as $name => $field ) {
|
719 |
-
if ( $name == $custom_field[
|
720 |
$new[ $key ] = $custom_field;
|
721 |
|
722 |
$new[ $name ] = $field;
|
@@ -747,9 +753,9 @@ class WC_GZD_Checkout {
|
|
747 |
|
748 |
foreach ( $this->custom_fields as $key => $custom_field ) {
|
749 |
|
750 |
-
if ( ! empty( $custom_field[
|
751 |
|
752 |
-
foreach ( $custom_field[
|
753 |
|
754 |
$val = '';
|
755 |
|
350 |
|
351 |
if ( $search && isset( $matches[1] ) ) {
|
352 |
$order_id = absint( $matches[1] );
|
353 |
+
$order = wc_get_order( $order_id );
|
354 |
+
$return = apply_filters( 'woocommerce_gzd_attempt_order_cancellation_url', add_query_arg( array( 'retry' => true ), $order->get_checkout_order_received_url(), $order ) );
|
355 |
}
|
356 |
|
357 |
return $return;
|
359 |
|
360 |
public function init_fields() {
|
361 |
if ( get_option( 'woocommerce_gzd_checkout_address_field' ) == 'yes' ) {
|
362 |
+
$this->custom_fields['title'] = array(
|
|
|
363 |
'type' => 'select',
|
364 |
'required' => false,
|
365 |
'label' => __( 'Title', 'woocommerce-germanized' ),
|
366 |
'options' => apply_filters( 'woocommerce_gzd_title_options', array( 1 => __( 'Mr.', 'woocommerce-germanized' ), 2 => __( 'Ms.', 'woocommerce-germanized' ) ) ),
|
367 |
'before' => 'first_name',
|
368 |
'group' => array( 'billing', 'shipping' ),
|
369 |
+
'priority' => 0,
|
370 |
);
|
371 |
|
372 |
+
$this->custom_fields_admin['title'] = array(
|
373 |
'before' => 'first_name',
|
374 |
'type' => 'select',
|
375 |
'options' => apply_filters( 'woocommerce_gzd_title_options', array( 1 => __( 'Mr.', 'woocommerce-germanized' ), 2 => __( 'Ms.', 'woocommerce-germanized' ) ) ),
|
376 |
'label' => __( 'Title', 'woocommerce-germanized' ),
|
377 |
'show' => false,
|
378 |
+
'priority' => 0,
|
379 |
);
|
|
|
380 |
}
|
381 |
|
382 |
if ( get_option( 'woocommerce_gzd_checkout_phone_required' ) == 'no' ) {
|
383 |
+
$this->custom_fields['phone'] = array(
|
|
|
384 |
'before' => '',
|
385 |
'override' => true,
|
386 |
'required' => false,
|
387 |
'group' => array( 'billing' )
|
388 |
);
|
|
|
389 |
}
|
390 |
|
391 |
$this->custom_fields_admin = apply_filters( 'woocommerce_gzd_custom_checkout_admin_fields', $this->custom_fields_admin, $this );
|
473 |
}
|
474 |
|
475 |
$fee->tax_data = $fee_taxes;
|
476 |
+
$fee->tax = wc_round_tax_total( $fee_tax_total );
|
477 |
+
$fee->amount = ( $fee->amount - $fee->tax );
|
478 |
$fee->total = $fee->amount;
|
479 |
|
480 |
$new_fees[ $key ] = $fee;
|
484 |
$cart->fees_api()->set_fees( $new_fees );
|
485 |
$cart->set_fee_tax( array_sum( $fee_tax_data ) );
|
486 |
$cart->set_fee_taxes( $fee_tax_data );
|
487 |
+
|
488 |
+
$fee_total = array_sum( wp_list_pluck( $new_fees, 'total' ) );
|
489 |
+
|
490 |
+
$cart->set_fee_total( wc_format_decimal( $fee_total, wc_get_price_decimals() ) );
|
491 |
}
|
492 |
}
|
493 |
|
526 |
// Calculate tax class share
|
527 |
if ( ! empty( $tax_shares ) ) {
|
528 |
$fee_taxes = array();
|
529 |
+
|
530 |
foreach ( $tax_shares as $rate => $class ) {
|
531 |
$tax_rates = WC_Tax::get_rates( $rate );
|
532 |
$tax_shares[ $rate ]['fee_tax_share'] = $fee->amount * $class['share'];
|
534 |
|
535 |
$fee_taxes += $tax_shares[ $rate ]['fee_tax'];
|
536 |
}
|
537 |
+
|
538 |
foreach ( $tax_shares as $rate => $class ) {
|
539 |
$cart->fees[ $key ]->tax_data = $cart->fees[ $key ]->tax_data + $class['fee_tax'];
|
540 |
}
|
541 |
+
|
542 |
// Add fee taxes to cart taxes
|
543 |
foreach ( array_keys( $cart->taxes + $fee_taxes ) as $sub ) {
|
544 |
$cart->taxes[ $sub ] = ( isset( $fee_taxes[ $sub ] ) ? $fee_taxes[ $sub ] : 0 ) + ( isset( $cart->taxes[ $sub ] ) ? $cart->taxes[ $sub ] : 0 );
|
545 |
}
|
546 |
+
|
547 |
// Update fee
|
548 |
+
$cart->fees[ $key ]->tax = wc_round_tax_total( array_sum( $cart->fees[ $key ]->tax_data ) );
|
549 |
+
$cart->fees[ $key ]->amount = wc_format_decimal( $cart->fees[ $key ]->amount - $cart->fees[ $key ]->tax, wc_get_price_decimals() );
|
550 |
}
|
551 |
}
|
552 |
}
|
624 |
return $fields;
|
625 |
|
626 |
if ( wc_gzd_get_crud_data( $order, 'billing_title' ) )
|
627 |
+
$fields['title'] = $this->get_customer_title( wc_gzd_get_crud_data( $order, 'billing_title' ) );
|
628 |
|
629 |
return $fields;
|
630 |
}
|
635 |
return $fields;
|
636 |
|
637 |
if ( wc_gzd_get_crud_data( $order, 'shipping_title' ) )
|
638 |
+
$fields['title'] = $this->get_customer_title( wc_gzd_get_crud_data( $order, 'shipping_title' ) );
|
639 |
|
640 |
return $fields;
|
641 |
}
|
658 |
}
|
659 |
|
660 |
public function set_formatted_address( $placeholder, $args ) {
|
661 |
+
if ( isset( $args['title'] ) ) {
|
662 |
+
$placeholder['{title}'] = $args['title'];
|
663 |
+
$placeholder['{title_upper}'] = strtoupper( $args['title'] );
|
664 |
+
$placeholder['{name}'] = $placeholder['{title}'] . ' ' . $placeholder['{name}'];
|
665 |
+
$placeholder['{name_upper}'] = $placeholder['{title_upper}'] . ' ' . $placeholder['{name_upper}'];
|
666 |
}
|
667 |
return $placeholder;
|
668 |
}
|
716 |
|
717 |
$new = array();
|
718 |
|
719 |
+
if ( isset( $custom_field['address_type'] ) && $custom_field['address_type'] !== $type )
|
720 |
continue;
|
721 |
|
722 |
if ( ! empty( $fields ) ) {
|
723 |
|
724 |
foreach ( $fields as $name => $field ) {
|
725 |
+
if ( $name == $custom_field['before'] && ! isset( $custom_field['override'] ) )
|
726 |
$new[ $key ] = $custom_field;
|
727 |
|
728 |
$new[ $name ] = $field;
|
753 |
|
754 |
foreach ( $this->custom_fields as $key => $custom_field ) {
|
755 |
|
756 |
+
if ( ! empty( $custom_field['group'] ) && ! isset( $custom_field['override'] ) ) {
|
757 |
|
758 |
+
foreach ( $custom_field['group'] as $group ) {
|
759 |
|
760 |
$val = '';
|
761 |
|
includes/class-wc-gzd-dhl-parcel-shops.php
CHANGED
@@ -21,7 +21,6 @@ class WC_GZD_DHL_Parcel_Shops {
|
|
21 |
}
|
22 |
|
23 |
public function __construct() {
|
24 |
-
|
25 |
$this->address_hooks();
|
26 |
|
27 |
if ( $this->is_enabled() ) {
|
@@ -144,7 +143,6 @@ class WC_GZD_DHL_Parcel_Shops {
|
|
144 |
}
|
145 |
|
146 |
public function init_fields( $fields ) {
|
147 |
-
|
148 |
$fields['parcelshop'] = array(
|
149 |
'type' => 'checkbox',
|
150 |
'required' => false,
|
@@ -153,6 +151,7 @@ class WC_GZD_DHL_Parcel_Shops {
|
|
153 |
'group' => array( 'shipping' ),
|
154 |
'class' => array( 'form-row-wide', 'first-check' ),
|
155 |
'hidden' => $this->maybe_hide_fields(),
|
|
|
156 |
);
|
157 |
|
158 |
$fields['parcelshop_post_number'] = array(
|
@@ -163,6 +162,7 @@ class WC_GZD_DHL_Parcel_Shops {
|
|
163 |
'group' => array( 'shipping' ),
|
164 |
'class' => array( 'form-row-wide' ),
|
165 |
'hidden' => $this->maybe_hide_fields(),
|
|
|
166 |
);
|
167 |
|
168 |
return $fields;
|
@@ -173,19 +173,20 @@ class WC_GZD_DHL_Parcel_Shops {
|
|
173 |
}
|
174 |
|
175 |
public function init_profile_fields( $fields ) {
|
176 |
-
|
177 |
$fields['shipping']['fields']['shipping_parcelshop'] = array(
|
178 |
'label' => __( 'DHL Parcel Shop?', 'woocommerce-germanized' ),
|
179 |
'type' => 'select',
|
180 |
'options' => array( 0 => __( 'No', 'woocommerce-germanized' ), 1 => __( 'Yes', 'woocommerce-germanized' ) ),
|
181 |
'description' => __( 'Select whether delivery to parcel shop should be enabled.', 'woocommerce-germanized' ),
|
182 |
'class' => '',
|
|
|
183 |
);
|
184 |
|
185 |
$fields['shipping']['fields']['shipping_parcelshop_post_number'] = array(
|
186 |
'label' => __( 'Postnumber', 'woocommerce-germanized' ),
|
187 |
'type' => 'text',
|
188 |
'description' => __( 'In case delivery to parcel shop is enabled please fill in the corresponding DHL post number.', 'woocommerce-germanized' ),
|
|
|
189 |
);
|
190 |
|
191 |
return $fields;
|
21 |
}
|
22 |
|
23 |
public function __construct() {
|
|
|
24 |
$this->address_hooks();
|
25 |
|
26 |
if ( $this->is_enabled() ) {
|
143 |
}
|
144 |
|
145 |
public function init_fields( $fields ) {
|
|
|
146 |
$fields['parcelshop'] = array(
|
147 |
'type' => 'checkbox',
|
148 |
'required' => false,
|
151 |
'group' => array( 'shipping' ),
|
152 |
'class' => array( 'form-row-wide', 'first-check' ),
|
153 |
'hidden' => $this->maybe_hide_fields(),
|
154 |
+
'priority' => 50,
|
155 |
);
|
156 |
|
157 |
$fields['parcelshop_post_number'] = array(
|
162 |
'group' => array( 'shipping' ),
|
163 |
'class' => array( 'form-row-wide' ),
|
164 |
'hidden' => $this->maybe_hide_fields(),
|
165 |
+
'priority' => 60,
|
166 |
);
|
167 |
|
168 |
return $fields;
|
173 |
}
|
174 |
|
175 |
public function init_profile_fields( $fields ) {
|
|
|
176 |
$fields['shipping']['fields']['shipping_parcelshop'] = array(
|
177 |
'label' => __( 'DHL Parcel Shop?', 'woocommerce-germanized' ),
|
178 |
'type' => 'select',
|
179 |
'options' => array( 0 => __( 'No', 'woocommerce-germanized' ), 1 => __( 'Yes', 'woocommerce-germanized' ) ),
|
180 |
'description' => __( 'Select whether delivery to parcel shop should be enabled.', 'woocommerce-germanized' ),
|
181 |
'class' => '',
|
182 |
+
'priority' => 50,
|
183 |
);
|
184 |
|
185 |
$fields['shipping']['fields']['shipping_parcelshop_post_number'] = array(
|
186 |
'label' => __( 'Postnumber', 'woocommerce-germanized' ),
|
187 |
'type' => 'text',
|
188 |
'description' => __( 'In case delivery to parcel shop is enabled please fill in the corresponding DHL post number.', 'woocommerce-germanized' ),
|
189 |
+
'priority' => 60,
|
190 |
);
|
191 |
|
192 |
return $fields;
|
includes/class-wc-gzd-shipping-rate.php
CHANGED
@@ -5,7 +5,6 @@ class WC_GZD_Shipping_Rate extends WC_Shipping_Rate {
|
|
5 |
public $tax_shares = array();
|
6 |
|
7 |
public function __construct( WC_Shipping_Rate $rate ) {
|
8 |
-
|
9 |
$num = 5;
|
10 |
|
11 |
try {
|
@@ -29,7 +28,6 @@ class WC_GZD_Shipping_Rate extends WC_Shipping_Rate {
|
|
29 |
}
|
30 |
|
31 |
public function set_shared_taxes() {
|
32 |
-
|
33 |
$cart = WC()->cart;
|
34 |
$this->tax_shares = wc_gzd_get_cart_tax_share();
|
35 |
|
@@ -37,28 +35,40 @@ class WC_GZD_Shipping_Rate extends WC_Shipping_Rate {
|
|
37 |
if ( ! empty( $this->tax_shares ) ) {
|
38 |
|
39 |
foreach ( $this->tax_shares as $rate => $class ) {
|
40 |
-
$tax_rates
|
41 |
$this->tax_shares[ $rate ]['shipping_tax_share'] = $this->cost * $class[ 'share' ];
|
42 |
-
$this->tax_shares[ $rate ]['shipping_tax']
|
43 |
}
|
44 |
|
45 |
-
$
|
46 |
|
47 |
foreach ( $this->tax_shares as $rate => $class ) {
|
48 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
50 |
}
|
51 |
}
|
52 |
|
53 |
public function set_costs() {
|
54 |
if ( WC()->cart->tax_display_cart === 'incl' ) {
|
55 |
-
$
|
56 |
|
57 |
if ( WC()->customer->is_vat_exempt() ) {
|
58 |
$shipping_rates = WC_Tax::get_shipping_tax_rates();
|
59 |
$shipping_taxes = WC_Tax::calc_inclusive_tax( $this->cost, $shipping_rates );
|
60 |
|
61 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
}
|
64 |
}
|
5 |
public $tax_shares = array();
|
6 |
|
7 |
public function __construct( WC_Shipping_Rate $rate ) {
|
|
|
8 |
$num = 5;
|
9 |
|
10 |
try {
|
28 |
}
|
29 |
|
30 |
public function set_shared_taxes() {
|
|
|
31 |
$cart = WC()->cart;
|
32 |
$this->tax_shares = wc_gzd_get_cart_tax_share();
|
33 |
|
35 |
if ( ! empty( $this->tax_shares ) ) {
|
36 |
|
37 |
foreach ( $this->tax_shares as $rate => $class ) {
|
38 |
+
$tax_rates = WC_Tax::get_rates( $rate );
|
39 |
$this->tax_shares[ $rate ]['shipping_tax_share'] = $this->cost * $class[ 'share' ];
|
40 |
+
$this->tax_shares[ $rate ]['shipping_tax'] = WC_Tax::calc_tax( ( $this->cost * $class[ 'share' ] ), $tax_rates, ( WC()->cart->tax_display_cart === 'incl' ) );
|
41 |
}
|
42 |
|
43 |
+
$taxes = array();
|
44 |
|
45 |
foreach ( $this->tax_shares as $rate => $class ) {
|
46 |
+
$taxes = array_map( 'wc_round_tax_total', $taxes + $class['shipping_tax'] );
|
47 |
+
}
|
48 |
+
|
49 |
+
if ( is_callable( array( $this, 'set_taxes' ) ) ) {
|
50 |
+
$this->set_taxes( $taxes );
|
51 |
+
} else {
|
52 |
+
$this->taxes = $taxes;
|
53 |
}
|
54 |
}
|
55 |
}
|
56 |
|
57 |
public function set_costs() {
|
58 |
if ( WC()->cart->tax_display_cart === 'incl' ) {
|
59 |
+
$cost = $this->cost - array_sum( $this->taxes );
|
60 |
|
61 |
if ( WC()->customer->is_vat_exempt() ) {
|
62 |
$shipping_rates = WC_Tax::get_shipping_tax_rates();
|
63 |
$shipping_taxes = WC_Tax::calc_inclusive_tax( $this->cost, $shipping_rates );
|
64 |
|
65 |
+
$cost = ( $cost - array_sum( $shipping_taxes ) );
|
66 |
+
}
|
67 |
+
|
68 |
+
if ( is_callable( array( $this, 'set_cost' ) ) ) {
|
69 |
+
$this->set_cost( wc_format_decimal( $cost, wc_get_price_decimals() ) );
|
70 |
+
} else {
|
71 |
+
$this->cost = wc_format_decimal( $cost, wc_get_price_decimals() );
|
72 |
}
|
73 |
}
|
74 |
}
|
includes/emails/class-wc-gzd-email-customer-processing-order.php
CHANGED
@@ -22,15 +22,18 @@ if ( ! class_exists( 'WC_GZD_Email_Customer_Processing_Order' ) ) :
|
|
22 |
public function __construct() {
|
23 |
parent::__construct();
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
$this->title = __( 'Order Confirmation', 'woocommerce-germanized' );
|
36 |
}
|
22 |
public function __construct() {
|
23 |
parent::__construct();
|
24 |
|
25 |
+
if ( wc_gzd_send_instant_order_confirmation() ) {
|
26 |
+
|
27 |
+
// Remove Triggers for parent email.
|
28 |
+
wc_gzd_remove_class_action( 'woocommerce_order_status_on-hold_to_processing_notification', 'WC_Email_Customer_Processing_Order', 'trigger', 10 );
|
29 |
+
wc_gzd_remove_class_action( 'woocommerce_order_status_pending_to_processing_notification', 'WC_Email_Customer_Processing_Order', 'trigger', 10 );
|
30 |
+
wc_gzd_remove_class_action( 'woocommerce_order_status_failed_to_processing_notification', 'WC_Email_Customer_Processing_Order', 'trigger', 10 );
|
31 |
+
|
32 |
+
// Remove Triggers for this email.
|
33 |
+
remove_action( 'woocommerce_order_status_failed_to_processing_notification', array( $this, 'trigger' ), 10 );
|
34 |
+
remove_action( 'woocommerce_order_status_on-hold_to_processing_notification', array( $this, 'trigger' ), 10 );
|
35 |
+
remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ), 10 );
|
36 |
+
}
|
37 |
|
38 |
$this->title = __( 'Order Confirmation', 'woocommerce-germanized' );
|
39 |
}
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Requires at least: 3.8
|
|
5 |
Tested up to: 5.0
|
6 |
WC requires at least: 2.4
|
7 |
WC tested up to: 3.5
|
8 |
-
Stable tag: 2.2.
|
9 |
Requires PHP: 5.3
|
10 |
License: GPLv3
|
11 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
@@ -184,6 +184,14 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider
|
|
184 |
|
185 |
== Changelog ==
|
186 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
= 2.2.3 =
|
188 |
* Fix: Woo 3.5 translation order processing email replacement
|
189 |
* Fix: Inline CSS was not applied due to hook priority issues
|
5 |
Tested up to: 5.0
|
6 |
WC requires at least: 2.4
|
7 |
WC tested up to: 3.5
|
8 |
+
Stable tag: 2.2.4
|
9 |
Requires PHP: 5.3
|
10 |
License: GPLv3
|
11 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
184 |
|
185 |
== Changelog ==
|
186 |
|
187 |
+
= 2.2.4 =
|
188 |
+
* Fix: Added priority to checkout fields to avoid undefined index error in Woo 3.5.1
|
189 |
+
* Fix: Do not remove default Woo order confirmation hooks if feature is disabled
|
190 |
+
* Fix: Order submit nonce naming fallback
|
191 |
+
* Improvement: Fee shared tax calculation
|
192 |
+
* Improvement: REST API boolean data handling
|
193 |
+
* Improvement: New REST API unit tests
|
194 |
+
|
195 |
= 2.2.3 =
|
196 |
* Fix: Woo 3.5 translation order processing email replacement
|
197 |
* Fix: Inline CSS was not applied due to hook priority issues
|
templates/checkout/order-submit.php
CHANGED
@@ -27,8 +27,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
27 |
<?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '">' . esc_html( $order_button_text ) . '</button>' ); ?>
|
28 |
|
29 |
<?php if ( $include_nonce ) :
|
30 |
-
|
31 |
-
wp_nonce_field( 'woocommerce-process_checkout', $nonce_name ); ?>
|
32 |
<?php endif; ?>
|
33 |
|
34 |
<?php do_action( 'woocommerce_review_order_after_submit' ); ?>
|
27 |
<?php echo apply_filters( 'woocommerce_order_button_html', '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="' . esc_attr( $order_button_text ) . '" data-value="' . esc_attr( $order_button_text ) . '">' . esc_html( $order_button_text ) . '</button>' ); ?>
|
28 |
|
29 |
<?php if ( $include_nonce ) :
|
30 |
+
wp_nonce_field( 'woocommerce-process_checkout', '_wpnonce' ); ?>
|
|
|
31 |
<?php endif; ?>
|
32 |
|
33 |
<?php do_action( 'woocommerce_review_order_after_submit' ); ?>
|
woocommerce-germanized.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WooCommerce Germanized
|
4 |
* Plugin URI: https://www.vendidero.de/woocommerce-germanized
|
5 |
* Description: WooCommerce Germanized extends WooCommerce to become a legally compliant store in the german market.
|
6 |
-
* Version: 2.2.
|
7 |
* Author: Vendidero
|
8 |
* Author URI: https://vendidero.de
|
9 |
* Requires at least: 3.8
|
@@ -31,7 +31,7 @@ final class WooCommerce_Germanized {
|
|
31 |
*
|
32 |
* @var string
|
33 |
*/
|
34 |
-
public $version = '2.2.
|
35 |
|
36 |
/**
|
37 |
* Single instance of WooCommerce Germanized Main Class
|
@@ -811,8 +811,10 @@ final class WooCommerce_Germanized {
|
|
811 |
}
|
812 |
|
813 |
// Try to prevent the On Hold Email from being sent even though it is called directly via the trigger method
|
814 |
-
if (
|
815 |
-
$mails['WC_Email_Customer_On_Hold_Order']
|
|
|
|
|
816 |
}
|
817 |
|
818 |
return $mails;
|
3 |
* Plugin Name: WooCommerce Germanized
|
4 |
* Plugin URI: https://www.vendidero.de/woocommerce-germanized
|
5 |
* Description: WooCommerce Germanized extends WooCommerce to become a legally compliant store in the german market.
|
6 |
+
* Version: 2.2.4
|
7 |
* Author: Vendidero
|
8 |
* Author URI: https://vendidero.de
|
9 |
* Requires at least: 3.8
|
31 |
*
|
32 |
* @var string
|
33 |
*/
|
34 |
+
public $version = '2.2.4';
|
35 |
|
36 |
/**
|
37 |
* Single instance of WooCommerce Germanized Main Class
|
811 |
}
|
812 |
|
813 |
// Try to prevent the On Hold Email from being sent even though it is called directly via the trigger method
|
814 |
+
if ( wc_gzd_send_instant_order_confirmation() ) {
|
815 |
+
if ( isset( $mails['WC_Email_Customer_On_Hold_Order'] ) ) {
|
816 |
+
$mails['WC_Email_Customer_On_Hold_Order'] = include 'includes/emails/class-wc-gzd-email-customer-on-hold-order.php';
|
817 |
+
}
|
818 |
}
|
819 |
|
820 |
return $mails;
|