it-source

WooCommerce Billing 양식에 사용자 정의 필드를 추가하시겠습니까?

criticalcode 2023. 10. 18. 22:11
반응형

WooCommerce Billing 양식에 사용자 정의 필드를 추가하시겠습니까?

WooCommerce Billing 양식에 사용자 정의 필드를 추가하는 코드를 받습니다.

필드가 표시되지만 문제는 필드에 nor도 없다는 것입니다.

내가 뭘 놓치고 있는 거지?기능에 이 코드를 추가했습니다.내 아이 테마에 php가 있습니다.

/*******************************
  CUSTOM BILLING FIELD
 ******************************** */
add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');

function custom_woocommerce_billing_fields($fields)
{

    $fields['billing']['billing_options'] = array(
        'label' => __('NIF', 'woocommerce'), // Add custom field label
        'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
        'required' => false, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'text', // add field type
        'class' => array('my-css')    // add class name
    );

    return $fields;
}

사용하시는 경우woocommerce_billing_fields그러면 자동으로 청구 필드에 할당되는 필드를 지정할 필요가 없습니다.하지만 당신이 사용하는 것은woocommerce_checkout_fields그런 다음 필드를 사용하도록 지정하기만 하면 됩니다.shipping아니면billing.

위해서woocommerce_billing_fields

add_filter('woocommerce_billing_fields', 'custom_woocommerce_billing_fields');

function custom_woocommerce_billing_fields($fields)
{

    $fields['billing_options'] = array(
        'label' => __('NIF', 'woocommerce'), // Add custom field label
        'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
        'required' => false, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'text', // add field type
        'class' => array('my-css')    // add class name
    );

    return $fields;
}


위해서woocommerce_checkout_fields

add_filter('woocommerce_checkout_fields', 'custom_woocommerce_billing_fields');

function custom_woocommerce_billing_fields($fields)
{
    $fields['billing']['billing_options'] = array(
        'label' => __('NIF', 'woocommerce'), // Add custom field label
        'placeholder' => _x('Your NIF here....', 'placeholder', 'woocommerce'), // Add custom field placeholder
        'required' => false, // if field is required or not
        'clear' => false, // add clear or not
        'type' => 'text', // add field type
        'class' => array('my-css')   // add class name
    );

    return $fields;
}

참조:

언급URL : https://stackoverflow.com/questions/42341548/add-a-custom-field-to-woocommerce-billing-form

반응형