Snippet issue with curcy | WordPress.org

[ad_1]

Hello, I am using the following snippet to not apply taxes to different payment methods, however, when using Curcy, the snippet does not work stably, when I change between payment methods the taxes are applied sometimes yes and sometimes not, any idea?

add_action( 'woocommerce_before_calculate_totals', 'change_tax_class_based_on_payment_method', 10, 1 );
function change_tax_class_based_on_payment_method( $cart ) {
    // Only for a specific defined payment meyhod
    if ( WC()->session->get('chosen_payment_method') !== 'cod' && WC()->session->get('chosen_payment_method') !== 'cheque' && WC()->session->get('chosen_payment_method') !== 'stripe_cc')
        return;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

    // Loop through cart items
    foreach( $cart->get_cart() as $cart_item ){
        // We set "Zero rate" tax class
        $cart_item['data']->set_tax_class("Zero rate");
    }
}

add_action('wp_footer', 'payment_methods_trigger_update_checkout');
function payment_methods_trigger_update_checkout() {
    if( is_checkout() && ! is_wc_endpoint_url() ) :
    ?>
    <script type="text/javascript">
        jQuery(function($){
            $( 'form.checkout' ).on('change', 'input[name="payment_method"]', function() {
                $(document.body).trigger('update_checkout');
            });
        });
    </script>
    <?php
    endif;
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer