VTMIN_Parent_Cart_Validation

VarkTech Minimum Purchase for WooCommerce Woo-specific functions Parent Plugin Integration.

Defined (1)

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

/woo-integration/vtmin-parent-cart-validation.php  
  1. class VTMIN_Parent_Cart_Validation { 
  2.  
  3. public function __construct() { 
  4. global $vtmin_info, $woocommerce; //$woocommerce_checkout = $woocommerce->checkout(); 
  5. /** =============+++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
  6. * Apply Minimum Amount Rules to ecommerce activity 
  7. *  
  8. * WOO-Specific Checkout Logic and triggers  
  9. *  
  10. * =============+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 
  11.  
  12. // add actions for early entry into Woo's 3 shopping cart-related pages, and the "place order" button - 
  13.  
  14. //if "place order" button hit, this action catches and errors as appropriate 
  15. add_action( 'woocommerce_before_checkout_process', array(&$this, 'vtmin_woo_check_click_to_pay') ); //v1.09.5  
  16.  
  17. //v1.09.5 changed to be direct, wp_loaded is correct!! ... 
  18. add_action( 'wp_loaded', array(&$this, 'vtmin_woo_apply_checkout_cntl'), 99, 1 ); //loaded passes no values, but needed for other call!!! 
  19.  
  20. //add_action( 'init', array(&$this, 'vtmin_woo_apply_checkout_cntl'), 99 );  
  21. //add_action( 'woocommerce_init', array(&$this, 'vtmin_woo_apply_checkout_cntl'), 99 ); 
  22. //add_action( 'woocommerce_loaded', array(&$this, 'vtmin_woo_apply_checkout_cntl'));  
  23.  
  24. //NEEDS WORK!!!!!!! 
  25. // deosn't work... add_action( 'woocommerce_cart_updated', array(&$this, 'vtmin_woo_apply_checkout_cntl'), 99 ); 
  26.  
  27. /** Priority of 99 in the action above, to delay add_action execution. The 
  28. priority delays us in the exec sequence until after any quantity change has 
  29. occurred, so we pick up the correct altered state. */  
  30.  
  31.  
  32. /** =============+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 
  33. //**********************************  
  34. //v1.09.5 refactored 
  35. //********************************** 
  36. public function vtmin_woo_check_click_to_pay() {  
  37.  
  38. global $vtmin_cart, $vtmin_cart_item, $vtmin_rules_set, $vtmin_rule, $vtmin_info, $woocommerce; 
  39. vtmin_debug_options(); //v1.09  
  40. $vtmin_apply_rules = new VTMIN_Apply_Rules;  
  41.  
  42. //v1.09.8 begin 
  43. if(!isset($_SESSION)) { 
  44. session_start(); 
  45. header("Cache-Control: no-cache"); 
  46. header("Pragma: no-cache"); 
  47.  
  48. //clears old messages first  
  49. if ( (isset ($_SESSION['error_message_sent'])) && 
  50. ($_SESSION['error_message_sent']) ) { 
  51. $_SESSION['error_message_sent'] = false; 
  52. wc_clear_notices();  
  53.  
  54. //v1.09.8 end 
  55.  
  56. //ERROR Message Path 
  57. if ( sizeof($vtmin_cart->error_messages) > 0 ) {  
  58.  
  59. //v1.08 changes begin 
  60. switch( $vtmin_cart->error_messages_are_custom ) {  
  61. case 'all': 
  62. $this->vtmin_display_custom_messages(); 
  63. break; 
  64. case 'some':  
  65. $this->vtmin_display_custom_messages(); 
  66. $this->vtmin_display_standard_messages(); 
  67.  
  68. //v1.09.5 begin  
  69. for($i=0; $i < sizeof($vtmin_cart->error_messages); $i++) {  
  70. if ($vtmin_cart->error_messages[$i]['msg_is_custom'] != 'yes') { //v1.08 ==>> don't show custom messages here...  
  71. $message = '<div class="vtmin-error" id="line-cnt' . $vtmin_info['line_cnt'] . '"><h3 class="error-title">Minimum Purchase Error</h3><p>' . $vtmin_cart->error_messages[$i]['msg_text']. '</p></div>'; 
  72. wc_add_notice( $message, 'error' ); 
  73. $_SESSION['error_message_sent'] = true; 
  74. //v1.09.5 begin 
  75.  
  76.  
  77. break;  
  78. default: //'none' / no state set yet 
  79. $this->vtmin_display_standard_messages(); 
  80. //v1.09.1 begin 
  81. //v1.09.5 REMOVED 
  82. /** 
  83. $current_version = WOOCOMMERCE_VERSION; 
  84. if( (version_compare(strval('2.1.0'), strval($current_version), '>') == 1) ) { //'==1' = 2nd value is lower  
  85. $woocommerce->add_error( __('Minimum Purchase error found.', 'vtmin') ); //supplies an error msg and prevents payment from completing  
  86. } else { 
  87. */ 
  88. //added in woo 2.1 
  89.  
  90. // wc_add_notice( __('Minimum Purchase error found.', 'vtmin'), 'error' ); //supplies an error msg and prevents payment from completing 
  91. // wc_add_notice( __('Minimum Purchase error found.', 'vtmin'), $notice_type = 'error' ); //supplies an error msg and prevents payment from completing  
  92.  
  93.  
  94. //v1.09.5 begin  
  95. for($i=0; $i < sizeof($vtmin_cart->error_messages); $i++) {  
  96. if ($vtmin_cart->error_messages[$i]['msg_is_custom'] != 'yes') { //v1.08 ==>> don't show custom messages here...  
  97. $message = '<div class="vtmin-error" id="line-cnt' . $vtmin_info['line_cnt'] . '"><h3 class="error-title">Minimum Purchase Error</h3><p>' . $vtmin_cart->error_messages[$i]['msg_text']. '</p></div>'; 
  98. wc_add_notice( $message, 'error' ); 
  99. $_SESSION['error_message_sent'] = true; 
  100. //v1.09.5 end  
  101.  
  102. // } //v1.09.5 REMOVED 
  103. //v1.09.1 end  
  104. break;  
  105.  
  106. //v1.08 changes end  
  107.  
  108. }  
  109.  
  110. return; 
  111.  
  112. }  
  113.  
  114. /** ************************************************ 
  115. ** Application - Apply Rules at E-Commerce Checkout 
  116. *************************************************** */ 
  117. public function vtmin_woo_apply_checkout_cntl() { //v1.0.9.4 added passed value 
  118.  
  119. //v1.09.5 begin 
  120. if (is_admin() ) { 
  121. return; 
  122.  
  123. //v1.09.5 end 
  124.  
  125. //v1.09.71 begin 
  126. if(!isset($_SESSION)) { 
  127. session_start(); 
  128. header("Cache-Control: no-cache"); 
  129. header("Pragma: no-cache"); 
  130. //v1.09.71 end 
  131.  
  132. global $vtmin_cart, $vtmin_cart_item, $vtmin_rules_set, $vtmin_rule, $vtmin_info, $woocommerce, $vtmin_setup_options; 
  133. vtmin_debug_options(); //v1.09  
  134. //input and output to the apply_rules routine in the global variables. 
  135. // results are put into $vtmin_cart 
  136.  
  137. /** v1.09.1 cart not there yet...  
  138. if ( $vtmin_cart->error_messages_processed == 'yes' ) {  
  139. wc_add_notice( __('Minimum Purchase error found.', 'vtmin'), $notice_type = 'error' ); //supplies an error msg and prevents payment from completing v1.09 
  140. return; 
  141. */ 
  142. //v1.0.9.4 begin 
  143. /** //v1.09.8 MOVED TO vt-maximum-purchase main file  
  144. $vtmin_info['woo_cart_url'] = $this->vtmin_woo_get_url('cart');  
  145. $vtmin_info['woo_checkout_url'] = $this->vtmin_woo_get_url('checkout'); 
  146. $vtmin_info['currPageURL'] = $this->vtmin_currPageURL(); 
  147. */  
  148.  
  149. if ( ($vtmin_setup_options['show_errors_on_all_pages'] == 'yes') && 
  150. (isset($woocommerce) ) && 
  151. (sizeof($woocommerce->cart->get_cart())>0) ) { //only process on woo pages - "is_woocommerce()" doesn't do the job 
  152. $carry_on; 
  153. } else { 
  154. $currPageURL = $vtmin_info['currPageURL']; 
  155. $woo_cart_url = $vtmin_info['woo_cart_url']; 
  156. $woo_checkout_url = $vtmin_info['woo_checkout_url']; 
  157.  
  158. // if an ITEM HAS BEEN REMOVED, url is apemnded to (&...) , can't look for equality - look for a substring 
  159. // (if CUSTOM MESSAGE not used, JS message does NOT come across in the situation where all was good, and then an item is removed) 
  160. if ( (strpos($currPageURL, $woo_cart_url ) !== false) || //BOOLEAN == true... 
  161. (strpos($currPageURL, $woo_checkout_url ) !== false) ) { //BOOLEAN == true... 
  162. //v1.09.5 end  
  163. $carry_on;  
  164.  
  165. } else {  
  166. return; 
  167. }  
  168. //v1.0.9.4 end 
  169.  
  170. //v1.09.8 begin clears old messages first  
  171. // wc_clear_notices DOES NOT WORK when a product is deleted!!!!!!!  
  172. if ( (isset ($_SESSION['error_message_sent'])) && 
  173. ($_SESSION['error_message_sent']) ) { 
  174. $_SESSION['error_message_sent'] = false; 
  175. wc_clear_notices();  
  176. //v1.09.8 end 
  177.  
  178. $vtmin_apply_rules = new VTMIN_Apply_Rules;  
  179.  
  180. //ERROR Message Path 
  181. if ( sizeof($vtmin_cart->error_messages) > 0 ) {  
  182.  
  183. //v1.08 changes begin 
  184. switch( $vtmin_cart->error_messages_are_custom ) {  
  185. case 'all': 
  186. $this->vtmin_display_custom_messages(); 
  187.  
  188. //$_SESSION['error_message_sent'] = true; //v1.09.71 removed v1.09.8 
  189.  
  190. break; 
  191. case 'some':  
  192. $this->vtmin_display_custom_messages(); 
  193. $this->vtmin_display_standard_messages(); 
  194.  
  195. //$_SESSION['error_message_sent'] = true; //v1.09.71 removed v1.09.8 
  196.  
  197. break;  
  198. default: //'none' / no state set yet 
  199. $this->vtmin_display_standard_messages(); 
  200. //v1.09.1 begin 
  201. //v1.09.5 REMOVED 
  202. /** 
  203. $current_version = WOOCOMMERCE_VERSION; 
  204. if( (version_compare(strval('2.1.0'), strval($current_version), '>') == 1) ) { //'==1' = 2nd value is lower  
  205. $woocommerce->add_error( __('Minimum Purchase error found.', 'vtmin') ); //supplies an error msg and prevents payment from completing  
  206. } else { 
  207. */ 
  208. //added in woo 2.1 
  209.  
  210. // wc_add_notice( __('Minimum Purchase error found.', 'vtmin'), 'error' ); //supplies an error msg and prevents payment from completing 
  211. // wc_add_notice( __('Minimum Purchase error found.', 'vtmin'), $notice_type = 'error' ); //supplies an error msg and prevents payment from completing  
  212.  
  213. // } //v1.09.5 REMOVED 
  214. //v1.09.1 end  
  215. break;  
  216.  
  217. //v1.08 changes end  
  218.  
  219.  
  220. }  
  221. /** moved above v1.09.8 
  222. else { //v1.09.71 begin 
  223. // CUSTOM messages can hang about after the issue has been cleared, - this takes care of it. 
  224. if ( (isset ($_SESSION['error_message_sent'])) && 
  225. ($_SESSION['error_message_sent']) ) { 
  226. $_SESSION['error_message_sent'] = false; 
  227. wc_clear_notices();  
  228. //v1.09.71 end 
  229. */ 
  230. }  
  231.  
  232.  
  233. /** ************************************************ 
  234. ** v1.08 New Function 
  235. *************************************************** */ 
  236. public function vtmin_display_standard_messages() { 
  237. global $vtmin_cart, $vtmin_cart_item, $vtmin_rules_set, $vtmin_rule, $vtmin_info, $woocommerce; 
  238. //insert error messages into checkout page 
  239. add_action( "wp_enqueue_scripts", array($this, 'vtmin_enqueue_error_msg_css') ); 
  240. add_action('wp_head', array(&$this, 'vtmin_display_rule_error_msg_at_checkout') ); //JS to insert error msgs  
  241.  
  242. $vtmin_cart->error_messages_processed = 'yes'; 
  243. }  
  244.  
  245. /** ************************************************ 
  246. ** v1.08 New Function 
  247. *************************************************** */ 
  248. public function vtmin_display_custom_messages() { 
  249. global $vtmin_cart, $vtmin_cart_item, $vtmin_rules_set, $vtmin_rule, $vtmin_info, $woocommerce; 
  250.  
  251. //v1.09.8 begin 
  252. if(!isset($_SESSION)) { 
  253. session_start(); 
  254. header("Cache-Control: no-cache"); 
  255. header("Pragma: no-cache"); 
  256. //v1.09.8 end 
  257.  
  258. for($i=0; $i < sizeof($vtmin_cart->error_messages); $i++) {  
  259. if ($vtmin_cart->error_messages[$i]['msg_is_custom'] == 'yes') { //v1.08 ==>> show custom messages here... 
  260. //v1.09.1 begin 
  261. $current_version = WOOCOMMERCE_VERSION; 
  262. if( (version_compare(strval('2.1.0'), strval($current_version), '>') == 1) ) { //'==1' = 2nd value is lower  
  263. $woocommerce->add_error( $vtmin_cart->error_messages[$i]['msg_text'] ); //supplies an error msg and prevents payment from completing  
  264. } else { 
  265. //added in woo 2.1 
  266. wc_add_notice( stripslashes($vtmin_cart->error_messages[$i]['msg_text']), $notice_type = 'error' ); //supplies an error msg and prevents payment from completing  
  267. $_SESSION['error_message_sent'] = true; //v1.09.8 end  
  268. }  
  269. //v1.09.1 end  
  270. } //end if 
  271. } //end 'for' loop  
  272. }  
  273.  
  274.  
  275. /** ************************************************ 
  276. ** Application - On Error Display Message on E-Commerce Checkout Screen  
  277. * //v1.09.5 REFACTORED  
  278. *************************************************** */  
  279. public function vtmin_display_rule_error_msg_at_checkout() { 
  280. global $vtmin_info, $vtmin_cart, $vtmin_setup_options; 
  281.  
  282. //v1.09.8 begin 
  283. if(!isset($_SESSION)) { 
  284. session_start(); 
  285. header("Cache-Control: no-cache"); 
  286. header("Pragma: no-cache"); 
  287. //v1.09.8 end  
  288.  
  289. for($i=0; $i < sizeof($vtmin_cart->error_messages); $i++) {  
  290. if ($vtmin_cart->error_messages[$i]['msg_is_custom'] != 'yes') { //v1.08 ==>> don't show custom messages here...  
  291. $message = '<div class="vtmin-error" id="line-cnt' . $vtmin_info['line_cnt'] . '"><h3 class="error-title">Minimum Purchase Error</h3><p>' . $vtmin_cart->error_messages[$i]['msg_text']. '</p></div>'; 
  292. wc_add_notice( $message, 'error' ); 
  293. $_SESSION['error_message_sent'] = true; //v1.09.8  
  294.  
  295.  
  296. /** *********************************** 
  297. CUSTOM ERROR MSG CSS AT CHECKOUT 
  298. *********************************** */ 
  299. if ($vtmin_setup_options[custom_error_msg_css_at_checkout] > ' ' ) { 
  300. echo '<style type="text/css">'; 
  301. echo $vtmin_setup_options[custom_error_msg_css_at_checkout]; 
  302. echo '</style>'; 
  303.  
  304. /** 
  305. Turn off the messages processed switch. As this function is only executed out 
  306. of wp_head, the switch is only cleared when the next screenful is sent. 
  307. */ 
  308. $vtmin_cart->error_messages_processed = 'no';  
  309. }  
  310.  
  311.  
  312. /** ************************************************ 
  313. ** Application - get current page url 
  314. *************************************************** */  
  315. /** 
  316. public function vtmin_currPageURL() { 
  317. $pageURL = 'http'; 
  318. if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} 
  319. $pageURL .= "://"; 
  320. if ($_SERVER["SERVER_PORT"] != "80") { 
  321. $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; 
  322. } else { 
  323. $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; 
  324. return $pageURL; 
  325. }  
  326. */ 
  327.  
  328.  
  329. /** ************************************************ 
  330. ** Application - On Error enqueue error style 
  331. *************************************************** */ 
  332. public function vtmin_enqueue_error_msg_css() { 
  333. wp_register_style( 'vtmin-error-style', VTMIN_URL.'/core/css/vtmin-error-style.css' );  
  334. wp_enqueue_style('vtmin-error-style'); 
  335. }  
  336.  
  337. } //end class