Guest User

Untitled

a guest
Oct 4th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. <?php
  2.  
  3. // guest registration
  4. function wc_register_guests( $order_id ) {
  5. // get all the order data
  6. $order = new WC_Order($order_id);
  7.  
  8. //get the user email from the order
  9. $order_email = $order->billing_email;
  10.  
  11. // check if there are any users with the billing email as user or email
  12. $email = email_exists( $order_email );
  13. $user = username_exists( $order_email );
  14.  
  15. // if the UID is null, then it's a guest checkout
  16. if( $user == false && $email == false ){
  17.  
  18. // random password with 12 chars
  19. $random_password = wp_generate_password();
  20.  
  21. // create new user with email as username & newly created pw
  22. $user_id = wp_create_user( $order_email, $random_password, $order_email );
  23. $user_id_role = new WP_User($user_id);
  24. $user_id_role->set_role('guest');
  25.  
  26. //WC guest customer identification
  27. update_user_meta( $user_id, 'guest', 'yes' );
  28.  
  29. //user's billing data
  30. update_user_meta( $user_id, 'billing_address_1', $order->billing_address_1 );
  31. update_user_meta( $user_id, 'billing_address_2', $order->billing_address_2 );
  32. update_user_meta( $user_id, 'billing_city', $order->billing_city );
  33. update_user_meta( $user_id, 'billing_company', $order->billing_company );
  34. update_user_meta( $user_id, 'billing_country', $order->billing_country );
  35. update_user_meta( $user_id, 'billing_email', $order->billing_email );
  36. update_user_meta( $user_id, 'billing_first_name', $order->billing_first_name );
  37. update_user_meta( $user_id, 'billing_last_name', $order->billing_last_name );
  38. update_user_meta( $user_id, 'billing_phone', $order->billing_phone );
  39. update_user_meta( $user_id, 'billing_postcode', $order->billing_postcode );
  40. update_user_meta( $user_id, 'billing_state', $order->billing_state );
  41.  
  42. // user's shipping data
  43. update_user_meta( $user_id, 'shipping_address_1', $order->shipping_address_1 );
  44. update_user_meta( $user_id, 'shipping_address_2', $order->shipping_address_2 );
  45. update_user_meta( $user_id, 'shipping_city', $order->shipping_city );
  46. update_user_meta( $user_id, 'shipping_company', $order->shipping_company );
  47. update_user_meta( $user_id, 'shipping_country', $order->shipping_country );
  48. update_user_meta( $user_id, 'shipping_first_name', $order->shipping_first_name );
  49. update_user_meta( $user_id, 'shipping_last_name', $order->shipping_last_name );
  50. update_user_meta( $user_id, 'shipping_method', $order->shipping_method );
  51. update_user_meta( $user_id, 'shipping_postcode', $order->shipping_postcode );
  52. update_user_meta( $user_id, 'shipping_state', $order->shipping_state );
  53.  
  54. // link past orders to this newly created customer
  55. wc_update_new_customer_past_orders( $user_id );
  56.  
  57. //start edit by Ramesh @campaignrabbit
  58. //pass the current user's data
  59. $old_user_data = $user_id_role;
  60. //trigger the profile_update event.
  61. do_action( 'profile_update', $user_id, $old_user_data );
  62. //end edit by Ramesh @campaignrabbit
  63. }
  64.  
  65. }
  66.  
  67. //add this newly created function to the thank you page
  68. add_action( 'woocommerce_thankyou', 'wc_register_guests', 10, 1 );
  69.  
  70.  
  71.  
  72. add_action( 'gform_user_registered', 'add_bday', 10, 3 );
  73. function add_bday( $user_id, $feed, $entry ) {
  74.  
  75. $form_id = $entry['form_id'];
  76.  
  77. switch ($form_id) {
  78. //wholesle registration via gform
  79. case 1:
  80. //do_action( 'profile_update', $user_id, $old_user_data );
  81. break;
  82.  
  83. //reward member registration gform
  84. case 3:
  85. $birthday = get_user_meta($user_id,'wpdv_birthday_calender',true);
  86.  
  87. if(!empty($birthday)){
  88. $birthday_var = explode('-',$birthday);
  89. $birthday_var = $birthday_var[1]."-".$birthday_var[2];
  90. update_user_meta($user_id,'wpdv_birthday',$birthday_var);
  91. }
  92. break;
  93. default:
  94. break;
  95. }
  96.  
  97. }
  98. ?>
Add Comment
Please, Sign In to add comment