retain_field_values_wccm

The WooCommerce Checkout Manager retain field values wccm function.

Description

retain_field_values_wccm(); 

Usage

  1. if ( !function_exists( 'retain_field_values_wccm' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/main.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = retain_field_values_wccm(); 
  7.  

Defined (1)

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

/includes/classes/main.php  
  1. function retain_field_values_wccm() {  
  2.  
  3. $options = get_option( 'wccs_settings' ); 
  4. $options2 = get_option( 'wccs_settings2' ); 
  5. $options3 = get_option( 'wccs_settings3' ); 
  6.  
  7.  
  8. if ( is_checkout() ) : 
  9.  
  10. $saved = WC()->session->get('wooccm_retain', array() ); 
  11. ?> 
  12.  
  13. <script type="text/javascript"> 
  14.  
  15. jQuery(document).ready(function() { 
  16.  
  17. window.onload = function() { 
  18.  
  19. <?php  
  20. if( !empty($options) ) { 
  21. foreach ( $options['buttons'] as $btn ) : 
  22. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  23. document.forms['checkout'].elements['<?php echo $btn['cow']; ?>'].value = "<?php echo $saved[''.$btn['cow'].'']; ?>"; 
  24.  
  25. <?php } 
  26. endforeach; 
  27.  
  28. if( !is_user_logged_in() ) { 
  29. if ( WC()->cart->needs_shipping_address() === true && $_POST['ship_to_different_address'] == 1 ) : 
  30. foreach ( $options2['shipping_buttons'] as $btn ) : 
  31. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  32. document.forms['checkout'].elements['shipping_<?php echo $btn['cow']; ?>'].value = "<?php echo $saved['shipping_'.$btn['cow'].'']; ?>"; 
  33.  
  34. <?php } 
  35. endforeach; 
  36. endif; 
  37.  
  38. foreach ( $options3['billing_buttons'] as $btn ) : 
  39. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  40. document.forms['checkout'].elements['billing_<?php echo $btn['cow']; ?>'].value = "<?php echo $saved['billing_'.$btn['cow'].'']; ?>"; 
  41.  
  42. <?php } 
  43. endforeach; 
  44. }  
  45.  
  46. ?> 
  47.  
  48. }  
  49. });  
  50. </script> 
  51.  
  52.  
  53.  
  54.  
  55.  
  56. <script type="text/javascript"> 
  57. jQuery(document).ready(function() { 
  58. jQuery('body').change(function() { 
  59.  
  60. var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; 
  61. data = { action: 'retain_val_wccs',  
  62.  
  63. <?php 
  64. if( !empty($options) ) { 
  65. foreach ( $options['buttons'] as $btn ) : 
  66. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  67. <?php echo $btn['cow']; ?>: jQuery("#<?php echo $btn['cow']; ?>").val(),  
  68.  
  69. <?php } 
  70. endforeach; 
  71.  
  72. if(!is_user_logged_in()) { 
  73. if ( WC()->cart->needs_shipping_address() === true && $_POST['ship_to_different_address'] == 1 ) :  
  74. foreach ( $options2['shipping_buttons'] as $btn ) : 
  75. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  76. shipping_<?php echo $btn['cow']; ?>: jQuery("shipping_<?php echo $btn['cow']; ?>").val(),  
  77.  
  78. <?php } 
  79. endforeach; 
  80. endif; 
  81.  
  82. foreach ( $options3['billing_buttons'] as $btn ) : 
  83. if ( $btn['type'] !== 'wooccmupload' && $btn['type'] !== 'changename' && $btn['type'] !== 'heading' && empty($btn['tax_remove']) && empty($btn['add_amount']) ) { ?> 
  84. billing_<?php echo $btn['cow']; ?>: jQuery("#billing_<?php echo $btn['cow']; ?>").val(),  
  85.  
  86. <?php } 
  87. endforeach; 
  88. ?> 
  89. }; 
  90.  
  91. jQuery.post(ajaxurl, data, function(response) { }); 
  92. return false; 
  93. }); 
  94. }); 
  95. </script> 
  96.  
  97.  
  98.  
  99. <?php  
  100. endif; 
  101.  
  102. }