设置结账时“state”字段非必填

/**
 * WooCommerce Extra Feature
 * --------------------------
 *
 * Make "state" field not required on checkout
 *
 */
 
add_filter( 'woocommerce_billing_fields', 'woo_filter_state_billing', 10, 1 );
add_filter( 'woocommerce_shipping_fields', 'woo_filter_state_shipping', 10, 1 );
 
function woo_filter_state_billing( $address_fields ) { 
  $address_fields['billing_state']['required'] = false;
  return $address_fields;
}
 
function woo_filter_state_shipping( $address_fields ) { 
  $address_fields['shipping_state']['required'] = false;
  return $address_fields;
}

在哪里添加此代码?

将PHP代码放在主题或子主题functions.php文件的底部。

发表我的评论

请输入你的评论!
请在这里输入你的名字

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据