Remove a checkout field if cart items are from some specific product categories

喜欢而已 提交于 2019-12-11 01:46:13

问题


I use WooCommerce Checkout Manager to add a custom field in my billing section, but I need to show this field only if I have some product from a specified category. The fields is required.

I wrote this code :

add_filter( 'woocommerce_checkout_fields' , 'wc_ninja_remove_checkout_field');
function wc_ninja_remove_checkout_field( $fields ) {
    $categories  = array( 'prodotti-in-polvere-e-bustine', 'gel-e-creme', 'prodotti-in-capsule', 'prodotti-plantari', 'prodotti-liquidi', 'area-riservata' );
    if ( is_product_category( array( $categories ) ) ) {
        unset( $fields['billing']['billing_myfield12'] );
    }
    return $fields;
}

This function just only set to display:none the field, in fact if I click on checkout there is an error like "the field myfield is required", but I need to remove my field not set to display none.

Please any idea?

I have the latest version of WooCommerce.

Thanks.

来源:https://stackoverflow.com/questions/40862982/remove-a-checkout-field-if-cart-items-are-from-some-specific-product-categories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!