提交订单后(保存数据之前),您可以使用以下内容删除/替换address\\u 1和address\\u 2 billing and shipping字段中的COMA:
// Checkout/Order: Remove/replace comas from adresses fields
add_action(\'woocommerce_checkout_create_order\', \'remove_comas_from_address_fields\', 10, 2 );
function remove_comas_from_address_fields( $order, $data ) {
$replacement = \'\';
if ( $billing_address_1 = $order->get_billing_address_1() ) {
$order->set_billing_address_1( str_replace( \',\', $replacement, $billing_address_1 ) );
}
if ( $billing_address_2 = $order->get_billing_address_2() ) {
$order->set_billing_address_2( str_replace( \',\', $replacement, $billing_address_2 ) );
}
if ( $shipping_address_1 = $order->get_shipping_address_1() ) {
$order->set_shipping_address_1( str_replace( \',\', $replacement, $shipping_address_1 ) );
}
if ( $shipping_address_2 = $order->get_shipping_address_2() ) {
$order->set_shipping_address_2( str_replace( \',\', $replacement, $shipping_address_2 ) );
}
}
代码进入功能。活动子主题(或活动主题)的php文件。已测试并正常工作。
如果您愿意,您也可以同时保留您的答案代码。这样,一切都将在操纵的情况下安全。