在 Woocommerce 结帐账单 phone 字段上使用 str_replace
Using str_replace on Woocommerce checkout billing phone field
在 WooCommerce 中,我想使用 str_replace()
.
替换 billing_phone 字段中的一些字符
我尝试了以下代码:
add_action( 'woocommerce_checkout_process', 'phone_replace' );
function phone_replace( $order_id ) {
if (! empty( $_POST['billing_phone'] ) ) {
str_replace( array('۱'), array('1'), $_POST['billing_phone'] );
}
}
但是没用。
哪个是正确的挂钩?
要在账单phone上使用str_replace()
,右勾总是一样的:
add_action( 'woocommerce_checkout_update_order_meta', 'update_order_meta_billing_phone' );
function update_order_meta_billing_phone( $order_id ) {
if ( ! empty( $_POST['billing_phone'] ) ) {
// Check and update
$billing_phone = str_replace( array('۱'), array('1'), $_POST['billing_phone'] );
update_post_meta( $order_id, '_billing_phone', sanitize_text_field( $phone_sabet ) );
## User data billing phone ##
// Get the user ID
$user_id = get_post_meta( $order_id, '_customer_user', true );
// Get the billing phone user data
$user_billing_phone = get_user_meta( $user_id, 'billing_phone', true );
// Check and update
if( ! empty ( $user_billing_phone ) ) {
$user_billing_phone = str_replace( array('۱'), array('1'), $user_billing_phone );
update_user_meta( $user_id, 'billing_phone', $user_billing_phone );
} else {
update_user_meta( $user_id, 'billing_phone', $billing_phone );
}
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
已测试并有效
在 WooCommerce 中,我想使用 str_replace()
.
我尝试了以下代码:
add_action( 'woocommerce_checkout_process', 'phone_replace' );
function phone_replace( $order_id ) {
if (! empty( $_POST['billing_phone'] ) ) {
str_replace( array('۱'), array('1'), $_POST['billing_phone'] );
}
}
但是没用。
哪个是正确的挂钩?
要在账单phone上使用str_replace()
,右勾总是一样的:
add_action( 'woocommerce_checkout_update_order_meta', 'update_order_meta_billing_phone' );
function update_order_meta_billing_phone( $order_id ) {
if ( ! empty( $_POST['billing_phone'] ) ) {
// Check and update
$billing_phone = str_replace( array('۱'), array('1'), $_POST['billing_phone'] );
update_post_meta( $order_id, '_billing_phone', sanitize_text_field( $phone_sabet ) );
## User data billing phone ##
// Get the user ID
$user_id = get_post_meta( $order_id, '_customer_user', true );
// Get the billing phone user data
$user_billing_phone = get_user_meta( $user_id, 'billing_phone', true );
// Check and update
if( ! empty ( $user_billing_phone ) ) {
$user_billing_phone = str_replace( array('۱'), array('1'), $user_billing_phone );
update_user_meta( $user_id, 'billing_phone', $user_billing_phone );
} else {
update_user_meta( $user_id, 'billing_phone', $billing_phone );
}
}
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
已测试并有效