Ecommerce Shopify WordPress Discussion

customer table returns empty after user registration in WordPress

Though data exists in both the wp_users and wp_wc_customer_lookup tables in mysql, I'm not sure what's wrong with this code. I'm using the below user_registration hook to fetch customer_id from 'wc_customer_lookup' after user registration and updating my custom table. add_action('user_register', 'map_customer_user', 10, 2); function map_customer_user($user_id) { if (isset($_COOKIE["uuid_custom"])) { global $wpdb; // Sanitize user input $user_id = intval($user_id); $table_name = $wpdb->prefix . 'custom_Table'; // Use prepare() to avoid SQL injection $customer = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $wpdb->prefix . "wc_customer_lookup WHERE user_id = %d", $user_id ) ); if ($customer) { $data_update = array( 'status' => 2, 'customer' => $customer->customer_id ); $data_where = array('customer_cookie_id' => $_COOKIE["uuid_custom"]); // Use $wpdb->update() to update data $wpdb->update($table_name, $data_update, $data_where); // Unset the cookie unset($_COOKIE["uuid_custom"]); setcookie('uuid_custom', '', time() - 3600, '/'); } else { // Handle case where customer data is not found } } }
Check if wc_customer_lookup table is being utilized: Guarantee Treat is Set Before the Client Enlistment: Debugging: // Example debugging statement error_log('User ID: ' . $user_id); Database Prefix: add_action('user_register', 'map_customer_user', 10, 1); function map_customer_user($user_id) { if (isset($_COOKIE["uuid_custom"])) { global $wpdb; // Sanitize user input $user_id = intval($user_id); // Use prepare() to avoid SQL injection $customer = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wc_customer_lookup WHERE user_id = %d", $user_id ) ); if ($customer) { $table_name = $wpdb->prefix . 'custom_Table'; $data_update = array( 'status' => 2, 'customer' => $customer->customer_id ); $data_where = array('customer_cookie_id' => $_COOKIE["uuid_custom"]); // Use $wpdb->update() to update data $wpdb->update($table_name, $data_update, $data_where); // Unset the cookie unset($_COOKIE["uuid_custom"]); setcookie('uuid_custom', '', time() - 3600, '/'); } else { // Handle case where customer data is not found error_log('Customer not found for user ID: ' . $user_id); } } }

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.