LP13
LP13

Reputation: 34159

How to change field's label on checkout page in woocommerce?

I am using wordpress for the first time. There is overwhelming information available about How to do stuff in WordPress. I want to simply change the label of postal code/zip field on check out page. Here are the steps i followed:

1>Installed woocommerce plugin
2>Imported Dummy Data
3>Installed Astra Starter Template Plugin
4>Installed Brandstore theme
5>Created my own child theme as per guidelines

Tested site. At this point everything working fine.

Now i want to simply change the lable for "Postalcode/Zip" on chekout page

So as per the woocommerce guidelines i added the following code in child theme's functions.php

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields',100 );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['billing']['billing_postcode']['label'] = 'Postal Code';
     return $fields;
}

When i refresh page it did not change the label.

Q1> How do i change field lable on checkout page.
Q2> where is template located for checkout page? Look like checkout page is using [woocommerce_checkout] code

Upvotes: 0

Views: 2204

Answers (2)

Vasanth Kumar s
Vasanth Kumar s

Reputation: 1

You can directly edit from woocommerce files but it is not recommended but the file path is :

wp-content/plugins/woocommerce/includes/class-wc-countries.php

Using hook is the best one to handle that woocommerce update will change all

// Hook to change post code in checkout page
add_filter('woocommerce_default_address_fields', 'custom_override_checkout_fields');

// Our hooked-in function - $fields is passed via the filter!
function custom_override_checkout_fields($fields) {
    $fields['postcode']['label'] = __( 'Postal Code', 'woocommerce' );
    return $fields;
}

Upvotes: 0

vijay pancholi
vijay pancholi

Reputation: 154

/**
 * Add the field to the checkout
 */

add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );


function my_custom_checkout_field( $checkout ) {


    echo '<div id="my_custom_checkout_field"><h2>' . __('My Field') . '</h2>';

    woocommerce_form_field( 'my_field_name', array(

        'type'          => 'text',

        'class'         => array('my-field-class form-row-wide'),

        'label'         => __('Fill in this field'),

        'placeholder'   => __('Enter something'),

        ), $checkout->get_value( 'my_field_name' ));


        echo '</div>';


}

/*For more information click on below documentation link */

https://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/

Upvotes: -2

Related Questions