Conditionally hide a Checkout field in WooCommerce based on chosen shipping

前端 未结 1 1764
滥情空心
滥情空心 2021-01-03 16:07

in WooCommerce, I am trying to hide the company name field whenever \"delivery to home\" is selected. I\'ve tried a bunch of different things.

This

1条回答
  •  有刺的猬
    2021-01-03 16:38

    As it's a live event, you need to use javascript/jQuery to make it work. The Billing company has to be not required like in default WooCommerce checkout page.

    The following code will hide the "Billing company" field, when "Home delivery" shipping is chosen:

    // Conditional Show hide checkout fields based on chosen shipping methods
    add_action( 'wp_footer', 'conditionally_hidding_billing_company' );
    function conditionally_hidding_billing_company(){
        // Only on checkout page
        if( ! is_checkout() ) return;
    
        // HERE your shipping methods rate ID "Home delivery"
        $home_delivery = 'pakkelabels_shipping_gls1';
        ?>
        
        

    Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and works.

    0 讨论(0)
提交回复
热议问题