简体   繁体   English

如何在 wordpress 的 woo commerce 我的帐户页面中添加电话号码屏蔽

[英]How to add phone number masking in woo commerce my account page in wordpress

I want to add phone number masking on my account page of Woocommerce in wordpress?我想在 wordpress 的 Woocommerce 的帐户页面上添加电话号码掩码?

Add the below code snippet in your active theme's functions.php file -在活动主题的函数中添加以下代码片段。php 文件 -

// Add field in Account Details
function wc_add_field_edit_account_form() {
    woocommerce_form_field(
        'user_phone_number',
        array(
            'type'        => 'tel',
            'required'    => true, // for false do not need this `woocommerce_save_account_details_required_fields` callback
            'label'       => __( 'Phone Number', 'yourtextdomain' ),
        ),
        get_user_meta( get_current_user_id(), 'user_phone_number', true ) 
    );
}
add_action( 'woocommerce_edit_account_form', 'wc_add_field_edit_account_form' );

// Save field data
function wc_save_account_details( $user_id ) {
    update_user_meta( $user_id, 'user_phone_number', wc_clean( $_POST[ 'user_phone_number' ] ) );
}
add_action( 'woocommerce_save_account_details', 'wc_save_account_details' );

// Add field required
function wc_add_account_details_required_fields( $required_fields ){
    $required_fields[ 'user_phone_number' ] = __( 'Phone Number', 'yourtextdomain' );
    return $required_fields;
}
add_filter( 'woocommerce_save_account_details_required_fields', 'wc_add_account_details_required_fields' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在woo-commerce我的帐户页面上添加其他表格 - Add extra form on woo-commerce My Account Page 在我的wordpress上安装Woo-commerce插件后,未创建我的帐户页面 - My Account Page does not created after installing Woo-commerce Plugin on my wordpress 具有页面限制的Wordpress woo Commerce - Wordpress woo commerce with page restrictions 如何在我自己的自定义产品-single.php页面中将woo commerce添加到购物车按钮 - how to out put woo commerce add to cart button in my own custom product-single.php page 如何将 Woo Commerce 中的变体选择添加到产品存档页面? - How to add variation selection in Woo commerce to the Products Archive page? 如何将Qwipi与Woo Commerce Wordpress集成 - How to integrate Qwipi with woo commerce wordpress Woo-commerce - 添加产品 - 列表页面 - 设计显示不正确 - Wordpress - Woo-commerce - Add Product - Listing Page - Design not showing properly - Wordpress Woo Commerce,如何编辑结帐页面 - Woo Commerce , how to edit checkout page 是否可以添加菜单项以在插件激活时吸引我的帐户页面? - is it possible to add menu items to woo commerce my accounts page on plugin activation? Wordpress-Woo Commerce确保每页产品一致 - Wordpress - Woo Commerce Ensure that products per page is consistent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM