dongli8722 2019-05-15 20:33
浏览 215

在WooCommerce结帐中对结算公司和特定结算国家/地区禁用税

In Woocommerce checkout, I am trying to remove tax if billing_company is not empty:

Here is my code

add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );

function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
        global $woocommerce;
        $woocommerce->customer->set_is_vat_exempt( false );
        $Pay_options=$_POST['Pay_options'];
        parse_str($post_data);
        global $woocommerce;

        if ( $billing_company != null) $woocommerce->customer->set_is_vat_exempt( true );
}

In IF statement I also need to check if billing_country is "Croatia".

How can I achieve this?

enter image description here

  • 写回答

2条回答 默认 最新

  • drpogkqqi536984960 2019-05-15 22:40
    关注

    Because on #billing_company change , there are no action to update checkout. So you need a javascript to do it

    add_action('woocommerce_after_checkout_form',function($checkout){
        ?>
        <script type="text/javascript">
        jQuery(function($){
            $(document).on('change','#billing_company',function(){
                $(document.body).trigger("update_checkout");
            });
        });
        </script>
        <?php
    });
    

    and in php, you can use your code, and user : $billing_country == 'HR' to check Croatia country

    add_action( 'woocommerce_checkout_update_order_review', 'bbloomer_taxexempt_checkout_based_on_zip' );
    
    function bbloomer_taxexempt_checkout_based_on_zip( $post_data ) {
            global $woocommerce;
            $woocommerce->customer->set_is_vat_exempt( false );
            $Pay_options=$_POST['Pay_options'];
            parse_str($post_data);
            if ( $billing_company != null) 
                $woocommerce->customer->set_is_vat_exempt( true );
            if($billing_country == 'HR'){ // Croatia
                // Do what you need, for example set TAX
                $woocommerce->customer->set_is_vat_exempt( false );
            }
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog