From c6c3eba567c23784f6ba57948a0f324e24b2fe31 Mon Sep 17 00:00:00 2001 From: vendidero Date: Thu, 12 Dec 2024 16:43:03 +0100 Subject: [PATCH] Check for VAT ID exempts before applying net prices for photovoltaic systems. --- includes/class-wc-gzd-checkout.php | 4 +++- .../class-wc-gzd-email-customer-paid-for-order.php | 2 +- includes/wc-gzd-core-functions.php | 3 ++- woocommerce-germanized.php | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/class-wc-gzd-checkout.php b/includes/class-wc-gzd-checkout.php index 15527461..f68e7847 100644 --- a/includes/class-wc-gzd-checkout.php +++ b/includes/class-wc-gzd-checkout.php @@ -334,6 +334,8 @@ public function maybe_adjust_photovoltaic_cart_data( $cart ) { if ( $checkbox = wc_gzd_get_legal_checkbox( 'photovoltaic_systems' ) ) { if ( $checkbox->is_enabled() ) { + $is_vat_exempt = WC()->customer && WC()->customer->is_vat_exempt(); + if ( $this->checkbox_is_checked( $checkbox ) && wc_gzd_cart_applies_for_photovoltaic_system_vat_exemption( $cart->get_cart() ) ) { foreach ( $cart->get_cart() as $cart_item_key => $values ) { $_product = apply_filters( 'woocommerce_cart_item_product', $values['data'], $values, $cart_item_key ); @@ -354,7 +356,7 @@ public function maybe_adjust_photovoltaic_cart_data( $cart ) { $_product->set_tax_class( get_option( 'woocommerce_gzd_photovoltaic_systems_zero_tax_class', 'zero-rate' ) ); } } - } elseif ( apply_filters( 'woocommerce_gzd_photovoltaic_systems_remove_zero_tax_class_for_non_exemptions', ( is_checkout() || $this->checkbox_is_visible( 'photovoltaic_systems' ) ) ) ) { + } elseif ( apply_filters( 'woocommerce_gzd_photovoltaic_systems_remove_zero_tax_class_for_non_exemptions', ( ! $is_vat_exempt && ( is_checkout() || $this->checkbox_is_visible( 'photovoltaic_systems' ) ) ) ) ) { foreach ( $cart->get_cart() as $cart_item_key => $values ) { $_product = apply_filters( 'woocommerce_cart_item_product', $values['data'], $values, $cart_item_key ); diff --git a/includes/emails/class-wc-gzd-email-customer-paid-for-order.php b/includes/emails/class-wc-gzd-email-customer-paid-for-order.php index 2882e3ed..7c2f72d6 100755 --- a/includes/emails/class-wc-gzd-email-customer-paid-for-order.php +++ b/includes/emails/class-wc-gzd-email-customer-paid-for-order.php @@ -100,7 +100,7 @@ public function trigger( $order_id ) { if ( $gateway ) { if ( $has_removed_hook && is_callable( array( $gateway, 'email_instructions' ) ) ) { - add_action( 'woocommerce_email_before_order_table', array( $gateway, 'email_instructions' ) ); + add_action( 'woocommerce_email_before_order_table', array( $gateway, 'email_instructions' ), 10, 3 ); } do_action( 'woocommerce_gzd_maybe_add_email_payment_instructions_after_removal', $this->object ); diff --git a/includes/wc-gzd-core-functions.php b/includes/wc-gzd-core-functions.php index d806a945..595d8554 100644 --- a/includes/wc-gzd-core-functions.php +++ b/includes/wc-gzd-core-functions.php @@ -1828,8 +1828,9 @@ function wc_gzd_get_photovoltaic_system_customer_location( $args = array() ) { function wc_gzd_customer_applies_for_photovoltaic_system_vat_exemption( $args = array() ) { $args = wc_gzd_get_photovoltaic_system_customer_location( $args ); $applies_for_photovoltaic_vat_exemption = false; + $is_vat_exempt = WC()->customer && WC()->customer->is_vat_exempt(); - if ( empty( $args['company'] ) || apply_filters( 'woocommerce_gzd_allow_b2b_photovoltaic_system_vat_exemption', false ) ) { + if ( ! $is_vat_exempt && ( empty( $args['company'] ) || apply_filters( 'woocommerce_gzd_allow_b2b_photovoltaic_system_vat_exemption', false ) ) ) { /** * Allow VAT exemption for: * - shipments to a country supporting photovoltaic exempts (from the base country or from another EU country which takes part in OSS procedure). diff --git a/woocommerce-germanized.php b/woocommerce-germanized.php index b521a374..bde3a0f4 100644 --- a/woocommerce-germanized.php +++ b/woocommerce-germanized.php @@ -1568,11 +1568,11 @@ public function add_gtin_fallback( $gtin, $product ) { public function add_structured_product_data( $markup, $product ) { if ( $gzd_product = wc_gzd_get_gzd_product( $product ) ) { - if ( ! isset( $markup['gtin'] ) || empty( $markup['gtin'] ) ) { - if ( $gtin = $gzd_product->get_gtin() ) { - $markup['gtin'] = $gtin; - } - } + if ( ! isset( $markup['gtin'] ) || empty( $markup['gtin'] ) ) { + if ( $gtin = $gzd_product->get_gtin() ) { + $markup['gtin'] = $gtin; + } + } if ( ! isset( $markup['mpn'] ) || empty( $markup['mpn'] ) ) { if ( $mpn = $gzd_product->get_mpn() ) {