首页 > 解决方案 > 选择其他运输方式时隐藏元素

问题描述

I tried to add a checkbox for a pick-up shipping method, so when the method is chosen, the tickbox appears and need to be validated but when the other shipping method is chosen, I want it to disappear. 当前,它没有得到验证,选择其他选项时,它都不会消失(主要问题)。

基于在 WooCommerce 3 答案中的特定运输方式下方添加复选框,这是我正在使用的代码:

add_action( 'woocommerce_after_shipping_rate', 'checkout_shipping_additional_field', 20, 2 );
function checkout_shipping_additional_field( $method, $index )
{
    if( $method->get_id() == 'pickup-location-method' ){
        echo '<br>
        <input type="checkbox" name="shipping_custom_1" id="shipping_custom_1" value="1" class="shipping_method shipping_custom_1">
        <label for="shipping_custom_1">I confirm that I'll attend the delivery.</label>';
    }
}

不幸的是,我有限的知识不允许我进一步使用此代码。你能帮我解决这个问题吗?

标签: javascriptphpwoocommerce

解决方案


推荐阅读