2017-09-28 46 views
1

在WooCommerce中,我想使用str_replace()替換billing_phone字段中的某些字符。在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']); 
    } 
} 

但它不工作。

這是正確的鉤子?

回答

1

到計費電話上使用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文件或也以任何插件文件。

測試和工程

相關問題