【发布时间】:2021-01-07 23:33:04
【问题描述】:
我使用 wooocmmerec 结帐字段编辑器插件创建了一个 woo-commerce 结帐字段,如下图 应该有条件地出现在结帐时,这里是启用它的代码。
function ga_checkout_fields($fields) {
global $user_country;
//$user_country = 'in'; //for test in dev
if( $user_country != 'in') { //hide gst if the location is not india
unset($fields['billing']['billing_gst_number']);
}
if( $user_country != 'br') { //hide taxid if the location is not brazil
unset($fields['billing']['billing_br_tax_id']);
}
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'ga_checkout_fields' );
此代码在结帐时完美运行,但问题是当用户尝试在我的帐户中编辑他们的帐单邮寄地址时,他们会看到那些自定义字段并且无法编辑他们的地址。我不想在我的帐户编辑帐单地址表单中向客户显示或保存自定义字段。 我尝试使用以下代码在我的帐户中取消设置帐单地址中的那些自定义字段,我可以隐藏这些字段但无法保存它们,因为结帐时需要税号字段。我希望在结帐时需要税号,并且我不想在我的帐户中的编辑帐单地址中有任何自定义字段?关于如何实现这一目标的任何见解?
function ga_remove_the_address_field( $address, $load_address ) {//this removes fields in the edit form
global $user_country;
if( $user_country != 'in') { //hide gst if the location is not india
unset($address['billing_gst_number']);
}
if( $user_country != 'br') { //hide taxid if the location is not brazil
unset($address['billing_br_tax_id']);
}
return $address;
}
add_filter( 'woocommerce_address_to_edit', 'ga_remove_the_address_field', 10, 2 );
【问题讨论】:
标签: php wordpress woocommerce field account