วิธีเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce
เผยแพร่แล้ว: 2021-05-24
คุณต้องการเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce แบบกำหนดเองหรือไม่? อ่านต่อเนื่องจากโพสต์นี้จะให้วิธีแก้ปัญหาง่ายๆ สำหรับคุณ
ไม่ใช่กระบวนการที่ซับซ้อนในการเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce อย่างไรก็ตาม คุณอาจต้องมีทักษะการเขียนโค้ดขั้นพื้นฐานเพื่อให้บรรลุเป้าหมายนี้ ได้ คุณสามารถใช้ปลั๊กอินได้ แต่อาจทำให้ไซต์ของคุณบวมได้ นี่เป็นวิธีปรับแต่งได้อย่างปลอดภัย
เรายังแนะนำให้สร้างธีมลูก เพื่อให้แน่ใจว่าการเปลี่ยนแปลงของคุณจะไม่สูญหายระหว่างการอัปเดต
เพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce
ในตอนท้ายของโพสต์นี้ คุณจะสามารถเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce ได้ เราได้สร้างข้อมูลโค้ดที่กำหนดเองเพื่อให้บรรลุเป้าหมายนี้ เราจะแนะนำคุณตลอดขั้นตอนทั้งหมดที่คุณต้องปฏิบัติตามเพื่อให้ผู้เริ่มต้นใช้งานโซลูชันนี้ได้ง่ายขึ้น
ให้เราได้รับสิทธิในมัน
ขั้นตอนในการเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce
ก่อนที่คุณจะดำเนินการต่อ อย่าลืมสำรองข้อมูลไซต์ของคุณ วิธีนี้จะช่วยให้คุณเปลี่ยนกลับเป็นเวอร์ชันก่อนหน้าได้หากเกิดปัญหาขึ้น
นี่คือขั้นตอนง่าย ๆ ที่คุณต้องปฏิบัติตาม:
- ลงชื่อเข้าใช้ไซต์ WordPress และเข้าถึง แดชบอร์ด ในฐานะผู้ดูแลระบบ
- จากเมนูแดชบอร์ด ให้คลิกที่ เมนูลักษณะที่ปรากฏ > เมนูตัวแก้ไขธีม เมื่อหน้าตัวแก้ไขธีมเปิดขึ้น ให้มองหาไฟล์ฟังก์ชันของธีมที่เราจะเพิ่มฟังก์ชันที่จะเพิ่มฟังก์ชันหมายเลข GTIN บนผลิตภัณฑ์ใน WooCommerce
- เพิ่มรหัสต่อไปนี้ ในไฟล์ php :
// this is just to prevent the user log in automatically after register
function wc_registration_redirect( $redirect_to ) {
wp_logout();
wp_redirect( '/sign-in/?q=');
exit;
}
// when user login, we will check whether this guy email is verify
function wp_authenticate_user( $userdata ) {
$isActivated = get_user_meta($userdata->ID, 'is_activated', true);
if ( !$isActivated ) {
$userdata = new WP_Error(
'inkfool_confirmation_error',
__( '<strong>ERROR:</strong> Your account has to be activated before you can login. You can resend by clicking <a href="/sign-in/?u='.$userdata->ID.'">here</a>', 'inkfool' )
);
}
&return $userdata;
}
// when a user register we need to send them an email to verify their account
function my_user_register($user_id) {
// get user data
$user_info = get_userdata($user_id);
// create md5 code to verify later
$code = md5(time());
// make it into a code to send it to user via email
$string = array('id'=>$user_id, 'code'=>$code);
// create the activation code and activation status
update_user_meta($user_id, 'is_activated', 0);
update_user_meta($user_id, 'activationcode', $code);
; // create the url
$url = get_site_url(). '/sign-in/?p=' .base64_encode( serialize($string));
// basically we will edit here to make this nicer
$html = 'Please click the following links <br/><br/> <a href="'.$url.'">'.$url.'</a>';
// send an email out to user
wc_mail($user_info->user_email, __('Please activate your account'), $html);
}
// we need this to handle all the getty hacks i made
function my_init(){
// check whether we get the activation message
if(isset($_GET['p'])){
$data = unserialize(base64_decode($_GET['p']));
$code = get_user_meta($data['id'], 'activationcode', true);
// check whether the code given is the same as ours
if($code == $data['code']){
// update the db on the activation process
update_user_meta($data['id'], 'is_activated', 1);
wc_add_notice( __( '<strong>Success:</strong> Your account has been activated! ', 'inkfool' )  );
}else{
wc_add_notice( __( '<strong>Error:</strong> Activation fails, please contact our administrator. ', 'inkfool' )  );
}
}
if(isset($_GET['q'])){
wc_add_notice( __( '<strong>Error:</strong> Your account has to be activated before you can login. Please check your email.', 'inkfool' ) );
}
if(isset($_GET['u'])){
my_user_register($_GET['u']);
wc_add_notice( __( '<strong>Succes:</strong> Your activation email has been resend. Please check your email.', 'inkfool' ) );
}
}
// hooks handler
add_action( 'init', 'my_init' );
add_filter('woocommerce_registration_redirect', 'wc_registration_redirect');
add_filter('wp_authenticate_user', 'wp_authenticate_user',10,2);
add_action('user_register', 'my_user_register',10,2);
บทสรุป
ถึงตอนนี้ ลูกค้าในร้านค้าของคุณควรยืนยันอีเมลของพวกเขาหลังจากลงทะเบียนเพื่อซื้อสินค้าในร้านค้าของคุณ รหัสนี้ได้รับการทดสอบและทำงานได้ดี

หากคุณมีปัญหาในการใช้งานโซลูชันนี้ คุณควรให้ผู้เชี่ยวชาญแทรกโค้ดให้คุณหรือใช้ปลั๊กอิน
เราหวังว่าโซลูชันนี้จะช่วยให้คุณเพิ่มการยืนยันอีเมลลงทะเบียน WooCommerce ได้
บทความที่คล้ายกัน
- ปลั๊กอินการจอง WordPress ที่ดีที่สุด 30 อันดับแรกสำหรับการจองออนไลน์
- วิธีเพิ่ม Wishlist ใน WooCommerce
- วิธีสร้าง Number Pagination ใน WordPress โดยไม่ต้องใช้ Plugin
- วิธีเปลี่ยนแท็กไลน์หน้าร้าน WooCommerce
- วิธีเพิ่มการเข้าสู่ระบบโซเชียลใน WooCommerce Social Login
- วิธีเพิ่มปุ่มดูรถเข็นใน WooCommerce
- วิธีเลือกทั้งหมดยกเว้นลูกสุดท้ายใน CSS » CSS ไม่ใช่ตัวอย่างลูกสุดท้าย
- วิธีการติดตั้ง Facebook Pixel บน WooCommerce
- วิธีส่งอีเมลเมื่อเปลี่ยนสถานะใน WooCommerce
- วิธีเปลี่ยนเทมเพลตอีเมลใน WooCommerce
- วิธีตรวจสอบว่าผู้ใช้ลงชื่อเข้าใช้ WordPress
- วิธีลบหมวดหมู่ที่ไม่มีหมวดหมู่ใน WordPress WooCommerce
- วิธีการตั้งค่า WooCommerce ซื้อหนึ่งแถมหนึ่ง
- วิธีเพิ่ม SKU ของผลิตภัณฑ์ใน WooCommerce
- วิธีลบชื่อหมวดหมู่สินค้า WooCommerce
- 30+ ปลั๊กอินการค้นหา WordPress ที่ดีที่สุดเพื่อปรับปรุงการค้นหาเว็บไซต์ของคุณ & SEO
- วิธีสร้างหน้าเข้าสู่ระบบและลงทะเบียนแยกต่างหากใน WooCommerce
