Created
October 12, 2021 23:42
-
-
Save hamidrezayazdani/5e83a9c8eb7e4ad4a5f38dd6d7cb5a30 to your computer and use it in GitHub Desktop.
هماهنگی افزونه دیجیتس با محصولات دانلودی ووکامرس
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Sync wc with DIGITS plugin | |
*/ | |
function ywp_sync_digits_with_wc( $customer_id, $new_customer_data, $password_generated ) { | |
$user = get_user_by( 'id', $customer_id ); | |
if ( $user && property_exists( $user, 'user_email' ) && empty( $user->user_email ) ) { | |
$fake_mail = sprintf( | |
'user_%d@%s', | |
$customer_id * 13, | |
ywp_cleanup_domain(), | |
); | |
wp_update_user( array( | |
'ID' => $customer_id, | |
'user_email' => sanitize_email( $fake_mail ), | |
) ); | |
} | |
} | |
add_action( 'woocommerce_created_customer', 'ywp_sync_digits_with_wc', 10, 3 ); | |
/** | |
* Remove url schema | |
*/ | |
funtion ywp_cleanup_domain() { | |
$home = get_home_url(); | |
$protocol = '#^http(s)?://#'; | |
$www = '/^www\./'; | |
$pure_domain = preg_replace( $protocol, '', $home ); | |
$pure_domain = preg_replace( $www, '', $home ); | |
return rtrim( $pure_domain, '/' ); | |
} | |
// The code goes to your active theme(or child theme) functions.php file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment