Support » Plugin: WooCommerce » Apply coupon and remove billing details field

  • Resolved sector13

    (@sector13)


    I’m interested in removing some of the billing details fields when a specific coupon is applied to the cart.

    I’ve successfully used this code (below), however the fields only change after I refresh the browser page. When the coupon code is applied the “your order” totals are dynamically updated but I can’t get the Billing Details to update.

    Is this custom Javascript or can this happen with WC actions?

    add_filter( 'woocommerce_checkout_fields' ,'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
        global $woocommerce;
        $coupon_id = 'cheeks';
    
        if (in_array($coupon_id, $woocommerce->cart->get_applied_coupons())) {
    
            //unset($fields['billing']['billing_first_name']);
            //unset($fields['billing']['billing_last_name']);
            unset($fields['billing']['billing_address_1']);
            unset($fields['billing']['billing_address_2']);
            unset($fields['billing']['billing_city']);
            unset($fields['billing']['billing_postcode']);
            unset($fields['billing']['billing_country']);
            unset($fields['billing']['billing_state']);
            unset($fields['billing']['billing_phone']);
            unset($fields['billing']['billing_company']);
            //unset($fields['billing']['billing_email']);
            unset($fields['order']['order_comments']);
        }
    
        return $fields;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Jess L

    (@jlundie)

    Hi @sector13,

    This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Plugin Support Hannah S. a11n

    (@fernashes)

    Automattic Happiness Engineer

    Hey there! No one has been able to chime in, so I’m going to close off this topic. If you need further support, I second Jess’ recommendations above.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.