WooCommerce Change Form Labels and Remove Fields

2019-02-24 19:40发布

I'm trying to customise WooCommerce checkout page, how can I edit field labels?

Also, how can I remove 2 fields from the form? I don't need Company and State field.

3条回答
欢心
2楼-- · 2019-02-24 20:05

Updating for future readers -

WooCommerce Docs now has a codex article on Customizing checkout fields using actions and filters which looks rather comprehensive.

The only additional point I will make is that as of WooCommerce 3.5.1 there is a small trick to using Billing/Shipping_Address_2 Labels, as addressed in my answer to this question.

查看更多
爷的心禁止访问
3楼-- · 2019-02-24 20:22

I recommend making a custom plugin that modifies this so you can easily upgrade WooCommerce at a later date.

In your custom plugin, implement some of the code found on here: http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/

For example, to remove Company and State:

// Hook in
add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
// Our Hooked in function - $fields is passed via the filter
function custom_override_checkout_fields( $fields) {
    unset($fields['shipping']['shipping_state']);
    unset($fields['shipping']['shipping_company']);
    return $fields;
}

If you need help making a Plugin, I made a guide on how to add custom fields to the Product page. I think it might be helpful in this context. http://www.xatik.com/2013/02/06/add-custom-form-woocommerce-product/

查看更多
Summer. ? 凉城
4楼-- · 2019-02-24 20:22

Here is a working hook that you need to add into your theme's functions.php file

add_filter( 'woocommerce_checkout_fields' , 'remove_checkout_fields' );

function remove_checkout_fields( $fields ) {
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_country']);
    return $fields;
}
查看更多
登录 后发表回答