function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
single.php
будет приоритетнее по отношению к single-product.php
в подпапке темыadd_filter( 'woocommerce_admin_billing_fields', 'custom_admin_billing_fields', 10, 1 );
function custom_admin_billing_fields( $billing_fields ) {
$billing_fields['first_name']['show'] = true;
$billing_fields['last_name']['show'] = true;
return $billing_fields;
}
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>
#order_data .order_data_column_container .address>p:first-of-type {
display: none;
}
</style>';
}
$order = new WC_Order($order_id);
$order_email = $order->billing_email;
$email = email_exists( $order_email );
$user = username_exists( $order_email );
$random_password = wp_generate_password();
$userdata = array(
'user_pass' => $random_password,
'user_login' => $order_email,
'first_name' => $order->billing_first_name,
'user_email' => $order_email,
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
add_action( 'woocommerce_thankyou', 'create_user_callback' );
function create_user_callback($order_id){
$order = wc_get_order( $order_id );
$order_detail['customer_first_name'] = get_post_meta( $order_id, '_billing_first_name', true );
$order_detail['customer_phone'] = get_post_meta( $order_id, '_billing_phone', true );
$order_detail['customer_email'] = get_post_meta( $order_id, '_billing_email', true );
$order_detail['customer_address'] = get_post_meta( $order_id, '_billing_address_2', true );
$customers = get_users( array( 'role' => 'customer' ) );
foreach( $customers as $customer ) :
$customers_email = get_user_meta( $customer->ID, 'billing_phone', true );
if($customers_phone!=$order_detail['customer_phone'] && $customer->user_email!=$order_detail['billing_email']) {
$userdata = array(
'user_pass' => '123',
'user_login' => $order_detail['customer_email'],
'first_name' => $order_detail['customer_first_name'],
'user_email' => $order_detail['customer_email'],
'role' => 'customer',
);
$userid = wp_insert_user( $userdata );
if ( !is_wp_error( $userid ) ) {
add_user_meta( $userid, 'billing_phone', $order_detail['customer_phone'] );
add_user_meta( $userid, 'billing_address_2', $order_detail['customer_address'] );
}
}
endforeach;
}
wc_update_new_customer_past_orders( $userid );
update_post_meta($order_id, '_customer_user', get_current_user_id());