簡體   English   中英

使插件創建的自定義結帳必填字段在 WooCommerce 中可選

[英]Make custom checkout required field created by plugin optional in WooCommerce

在 woocommerce 結賬頁面需要去掉特定的自定義字段驗證。 該字段基本上是由使用 woocommerce_form_field() 的插件生成的。有沒有辦法刪除該特定字段的驗證?這段代碼塊

echo '<div id="woo_delivery_delivery_selection_field" style="display:none;">';
            woocommerce_form_field('woo_delivery_delivery_selection_box',
            [
                'type' => 'select',
                'class' => [
                    'woo_delivery_delivery_selection_box form-row-wide'
                ],
                'label' => __($delivery_option_field_label, 'woo-delivery'),
                'placeholder' => __($delivery_option_field_label, 'woo-delivery'),
                'options' => Woo_Delivery_Delivery_Option::delivery_option($delivery_option_settings),
                'required' => true,
                'custom_attributes' => [
                    'data-no_result_notice' => __($no_result_notice, 'woo-delivery'),
                ],
            ], WC()->checkout->get_value('woo_delivery_delivery_selection_box'));
        echo '</div>'

您需要在您的functions.php中測試類似的代碼。php 的子主題或活動主題


add_filter( 'woocommerce_checkout_fields', 'remove_validation_from_field', PHP_INT_MAX, 1 );
 
function remove_validation_from_field( $woo_checkout_fields_array ) {
    // use unset to remove the validation from your desired field
    // like I am removing the phone number validation from billing address
    unset( $woo_checkout_fields_array['billing']['billing_phone']['validate'] );
    return $woo_checkout_fields_array;
}
add_filter( 'woocommerce_checkout_fields' , 'woocommerce_form_fields' );
                
function  woocommerce_form_fields( $fields ) {
$fields['billing']['billing_first_name']['required'] = false;
return $fields;
}

實際上我們需要使用過濾鈎 woocommerce_checkout_fields 並且需要根據帳單,運輸,帳戶,訂單進行修改。 有關更多詳細信息,您可以訪問https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM