3

我正在尝试自定义 WooCommerce 结帐页面,如何编辑字段标签?

另外,如何从表单中删除 2 个字段?我不需要CompanyState领域。

4

3 回答 3

5

我建议制作一个自定义插件来修改它,以便您以后可以轻松升级 WooCommerce。

在您的自定义插件中,实现此处的一些代码: http ://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/

例如,要删除公司和州:

// 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;
}

如果您在制作插件时需要帮助,我制作了有关如何将自定义字段添加到产品页面的指南。我认为这在这种情况下可能会有所帮助。 http://www.xatik.com/2013/02/06/add-custom-form-woocommerce-product/

于 2013-02-12T19:28:34.107 回答
1

这是您需要添加到主题的 functions.php 文件中的工作挂钩

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;
}
于 2016-10-11T12:28:11.970 回答
0

为未来的读者更新 -

WooCommerce Docs 现在有一篇关于使用操作和过滤器自定义结帐字段的法典文章,看起来相当全面。

我要补充的唯一一点是,从 WooCommerce 3.5.1 开始,使用 Billing/Shipping_Address_2 标签有一个小技巧,正如我对这个问题的回答中所述。

于 2018-11-02T03:39:42.170 回答