wc_delete_user_data()
When a user is deleted in WordPress, delete corresponding WooCommerce data.
No Hooks.
Return
null
. Nothing (null).
Usage
wc_delete_user_data( $user_id );
- $user_id(int) (required)
- User ID being deleted.
wc_delete_user_data() wc delete user data code WC 9.4.2
function wc_delete_user_data( $user_id ) { global $wpdb; // Clean up sessions. $wpdb->delete( $wpdb->prefix . 'woocommerce_sessions', array( 'session_key' => $user_id, ) ); // Revoke API keys. $wpdb->delete( $wpdb->prefix . 'woocommerce_api_keys', array( 'user_id' => $user_id, ) ); // Clean up payment tokens. $payment_tokens = WC_Payment_Tokens::get_customer_tokens( $user_id ); foreach ( $payment_tokens as $payment_token ) { $payment_token->delete(); } }