滑动继续阅读⇓

如何从WooCommerce中删除账单字段

当你使用WooCommerce商店销售数字或虚拟或任何产品时,你可能不需要所有结算字段。

我收到了很多关于这个特定“问题”的请求,所以这里是你如何安全地删除默认的WooCommerce结算字段的方法。

有两种方法*:

  1. 通过安装插件My Custom Functions并在外观 -> Custom Functions中添加以下代码
  2. 通过将此代码段添加到你的主题functions.php文件中

请注意,在你的实时站点上编辑主题functions.php文件可能存在风险。因此,除非你知道自己在做什么,或者至少可以访问cPanel或FTP,否则建议你选择#1。

删除默认WooCommerce结算字段的代码段如下:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
 
function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);
    unset($fields['order']['order_comments']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_email']);
    unset($fields['billing']['billing_city']);
    return $fields;
}

所以如果你只想删除计费电话,那么代码片段看起来像这样:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
 
function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_phone']);
    return $fields;
}

就这样!几行代码,你可以在几分钟内删除WooCommerce结算字段!如果你输入错误并且无法返回WordPress,请使用FTP编辑你的functions.php文件并修复或删除代码。

如果你正在寻找更多定制,我们还创建了一篇关于如何重新排序你的账单字段的帖子。

*2022年更新:WooCommerce现在可以删除字段而无需触碰一行代码!该插件还允许你从插件仪表板添加新的或编辑账单字段。

本文是否有帮助?



iTopVPN Black Friday Deal - Save up to 90%