evolve_woocommerce_before_my_account

The evolve evolve woocommerce before my account function.

Description

evolve_woocommerce_before_my_account( $args ); 

Parameters (1)

0. $args
The args.

Usage

  1. if ( !function_exists( 'evolve_woocommerce_before_my_account' ) ) { 
  2. require_once '/library/woo-config.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = evolve_woocommerce_before_my_account($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/library/woo-config.php  
  1. function evolve_woocommerce_before_my_account($args) { 
  2. $address_session = ''; 
  3. if (isset($_SESSION['formvalue'])) { 
  4. $address_session = 'style="display:block"'; 
  5. ?> 
  6. <div class="myaccount_address" id="change_address" <?php echo $address_session; ?>> 
  7. <h2 class="edit_address_heading" <?php echo $address_session; ?>><?php echo apply_filters('woocommerce_my_account_edit_address_title', 'My Address'); ?></h2> 
  8. <?php 
  9. $customer_id = get_current_user_id(); 
  10.  
  11. if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) { 
  12. $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array( 
  13. 'billing' => __('Billing Address', 'evolve'),  
  14. 'shipping' => __('Shipping Address', 'evolve') 
  15. ), $customer_id); 
  16. } else { 
  17. $get_addresses = apply_filters('woocommerce_my_account_get_addresses', array( 
  18. 'billing' => __('Billing Address', 'evolve') 
  19. ), $customer_id); 
  20.  
  21. $oldcol = 1; 
  22. $col = 1; 
  23. ?> 
  24.  
  25. <p> 
  26. <?php echo apply_filters('woocommerce_my_account_my_address_description', __('The following addresses will be used on the checkout page by default.', 'evolve')); ?> 
  27. </p> 
  28.  
  29. <?php 
  30. if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) 
  31. echo '<div class="u-columns woocommerce-Addresses col2-set">'; 
  32.  
  33. foreach ($get_addresses as $name => $title) : 
  34. ?> 
  35.  
  36. <div class="u-column<?php echo ( ( $col = $col * -1 ) < 0 ) ? 1 : 2; ?> col-<?php echo ( ( $oldcol = $oldcol * -1 ) < 0 ) ? 1 : 2; ?> woocommerce-Address"> 
  37. <header class="woocommerce-Address-title title"> 
  38. <h3><?php echo $title; ?></h3> 
  39. <a href="#" data-name="<?php echo $name; ?>" id="editaddress_<?php echo $name; ?>" class="edit woo_editaddress"><?php _e('Edit', 'evolve'); ?></a> 
  40. </header> 
  41. <address> 
  42. <?php 
  43. $address = apply_filters('woocommerce_my_account_my_address_formatted_address', array( 
  44. 'first_name' => get_user_meta($customer_id, $name . '_first_name', true),  
  45. 'last_name' => get_user_meta($customer_id, $name . '_last_name', true),  
  46. 'company' => get_user_meta($customer_id, $name . '_company', true),  
  47. 'address_1' => get_user_meta($customer_id, $name . '_address_1', true),  
  48. 'address_2' => get_user_meta($customer_id, $name . '_address_2', true),  
  49. 'city' => get_user_meta($customer_id, $name . '_city', true),  
  50. 'state' => get_user_meta($customer_id, $name . '_state', true),  
  51. 'postcode' => get_user_meta($customer_id, $name . '_postcode', true),  
  52. 'country' => get_user_meta($customer_id, $name . '_country', true) 
  53. ), $customer_id, $name); 
  54.  
  55. $formatted_address = WC()->countries->get_formatted_address($address); 
  56.  
  57. if (!$formatted_address) 
  58. _e('You have not set up this type of address yet.', 'evolve'); 
  59. else 
  60. echo $formatted_address; 
  61. ?> 
  62. </address> 
  63. </div> 
  64.  
  65. <?php 
  66. endforeach; 
  67.  
  68. if (!wc_ship_to_billing_address_only() && wc_shipping_enabled()) 
  69. echo '<div class="clear"></div></div>'; 
  70.  
  71. $load_address = 'billing'; 
  72. $current_user = wp_get_current_user(); 
  73. $address = WC()->countries->get_address_fields(get_user_meta(get_current_user_id(), $load_address . '_country', true), $load_address . '_'); 
  74. // Prepare values 
  75. foreach ($address as $key => $field) { 
  76. $value = get_user_meta(get_current_user_id(), $key, true); 
  77.  
  78. if (!$value) { 
  79. switch ($key) { 
  80. case 'billing_email' : 
  81. case 'shipping_email' : 
  82. $value = $current_user->user_email; 
  83. break; 
  84. case 'billing_country' : 
  85. case 'shipping_country' : 
  86. $value = WC()->countries->get_base_country(); 
  87. break; 
  88. case 'billing_state' : 
  89. case 'shipping_state' : 
  90. $value = WC()->countries->get_base_state(); 
  91. break; 
  92.  
  93. $address[$key]['value'] = apply_filters('woocommerce_my_account_edit_address_field_value', $value, $key, $load_address); 
  94.  
  95. $addressform_session = ''; 
  96. if (isset($_SESSION['formvalue']) && !empty($field['required']) && isset($_POST[$key])) { 
  97. $addressform_session = 'style=display:block'; 
  98. } elseif (isset($_SESSION['formvalue'])) { 
  99. $addressform_session = 'style=display:none'; 
  100. ?> 
  101. <h3 class="editaddress_billing" <?php echo $addressform_session; ?>><?php _e('Billing Address', 'evolve'); ?></h3> 
  102. <div class="editaddress_billing" <?php echo $addressform_session; ?>> 
  103. <form method="post"> 
  104.  
  105. <?php 
  106. foreach ($address as $key => $field) : 
  107.  
  108. woocommerce_form_field($key, $field, !empty($_POST[$key]) ? wc_clean($_POST[$key]) : $field['value'] ); 
  109.  
  110. endforeach; 
  111. ?> 
  112.  
  113. <p> 
  114. <input type="submit" class="button small default alignright" id="saveaddress" name="save_address" value="<?php _e('Save Address', 'evolve'); ?>" /> 
  115. <?php wp_nonce_field('woocommerce-edit_address'); ?> 
  116. <input type="hidden" name="action" value="edit_address" /> 
  117. <input type="hidden" name="formvalue" value="billing" /> 
  118. <div class="clearboth"></div> 
  119. </p> 
  120.  
  121. </form> 
  122. </div> 
  123.  
  124. <?php 
  125. $load_address = 'shipping'; 
  126. $current_user = wp_get_current_user(); 
  127. $address = WC()->countries->get_address_fields(get_user_meta(get_current_user_id(), $load_address . '_country', true), $load_address . '_'); 
  128. // Prepare values 
  129. foreach ($address as $key => $field) { 
  130.  
  131. $value = get_user_meta(get_current_user_id(), $key, true); 
  132.  
  133. if (!$value) { 
  134. switch ($key) { 
  135. case 'billing_email' : 
  136. case 'shipping_email' : 
  137. $value = $current_user->user_email; 
  138. break; 
  139. case 'billing_country' : 
  140. case 'shipping_country' : 
  141. $value = WC()->countries->get_base_country(); 
  142. break; 
  143. case 'billing_state' : 
  144. case 'shipping_state' : 
  145. $value = WC()->countries->get_base_state(); 
  146. break; 
  147.  
  148. $address[$key]['value'] = apply_filters('woocommerce_my_account_edit_address_field_value', $value, $key, $load_address); 
  149.  
  150. $addressform_session = ''; 
  151. if (isset($_SESSION['formvalue']) && !empty($field['required']) && isset($_POST[$key])) { 
  152. $addressform_session = 'style=display:block'; 
  153. } elseif (isset($_SESSION['formvalue'])) { 
  154. $addressform_session = 'style=display:none'; 
  155. ?> 
  156. <h3 class="editaddress_shipping" <?php echo $addressform_session; ?>><?php _e('Shipping Address', 'evolve'); ?></h3> 
  157. <div class="editaddress_shipping" <?php echo $addressform_session; ?>> 
  158. <form method="post"> 
  159.  
  160. <?php 
  161. foreach ($address as $key => $field) : 
  162.  
  163. woocommerce_form_field($key, $field, !empty($_POST[$key]) ? wc_clean($_POST[$key]) : $field['value'] ); 
  164.  
  165. endforeach; 
  166. ?> 
  167.  
  168. <p> 
  169. <input type="submit" class="button small default alignright" id="saveaddress" name="save_address" value="<?php _e('Save Address', 'evolve'); ?>" /> 
  170. <?php wp_nonce_field('woocommerce-edit_address'); ?> 
  171. <input type="hidden" name="action" value="edit_address" /> 
  172. <input type="hidden" name="formvalue" value="shipping" /> 
  173. <div class="clearboth"></div> 
  174. </p> 
  175.  
  176. </form> 
  177. </div> 
  178. </div> 
  179. <?php 
  180. unset($_SESSION['formvalue']);