2017-09-28 13 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']); 
    } 
} 

しかし、それは動作しません。

これは正しいフックですか?課金電話でstr_replace()を使用するに

答えて

1

は、右フックは常に同じです:

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ファイルに行きますか。

試験済みで動作します。

関連する問題