/wcpgsk-af.php

  1. <?php 
  2. if ( ! defined( 'ABSPATH' ) ) exit; 
  3. /** 
  4. * Execute actions and filters 
  5. * Checks for standard configured actions and filters and attaches these actions and filters 
  6. * 
  7. */ 
  8. global $wcpgsk_options; 
  9.  
  10. add_filter( 'woocommerce_add_to_cart_validation', 'wcpgsk_maxitems_in_cart', 10, 3 ); 
  11. add_filter( 'woocommerce_update_cart_validation', 'wcpgsk_minitems_in_cart', 2, 4 ); 
  12. add_filter( 'woocommerce_add_to_cart_validation', 'wcpgsk_globalqty_cart_add', 1, 3 ); 
  13. add_filter( 'woocommerce_update_cart_validation', 'wcpgsk_globalqty_cart_update', 1, 4 ); 
  14. add_filter( 'woocommerce_is_sold_individually', 'wcpgsk_check_qty_config', 10, 2 ); 
  15. add_filter( 'woocommerce_quantity_input_max', 'wcpgsk_qtyselector_max', 10, 2 ); 
  16. add_filter( 'woocommerce_quantity_input_min', 'wcpgsk_qtyselector_min', 10, 2 ); 
  17. add_filter( 'woocommerce_quantity_input_step', 'wcpgsk_quantity_input_step', 10, 2 ); 
  18. //add_filter( 'woocommerce_quantity_input_args', 'wcpgsk_qty_input_args', 10, 2 ); 
  19. if ( function_exists('WC') ) : 
  20. add_filter( 'woocommerce_product_single_add_to_cart_text', 'wcpgsk_product_single_cart_button_text', 10, 2 ); 
  21. add_filter( 'woocommerce_product_add_to_cart_text', 'wcpgsk_product_cart_button_text', 10, 2 ); 
  22. else : 
  23. add_filter( 'single_add_to_cart_text', 'wcpgsk_single_cart_button_text', 10, 2 ); 
  24. add_filter( 'variable_add_to_cart_text', 'wcpgsk_variable_cart_button_text', 10, 1 ); 
  25. add_filter( 'grouped_add_to_cart_text', 'wcpgsk_grouped_cart_button_text', 10, 1 ); 
  26. add_filter( 'external_add_to_cart_text', 'wcpgsk_external_cart_button_text', 10, 1 ); 
  27. add_filter( 'out_of_stock_add_to_cart_text', 'wcpgsk_outofstock_cart_button_text', 10, 1 ); 
  28. add_filter( 'add_to_cart_text', 'wcpgsk_cart_button_text', 10, 1 ); 
  29. endif; 
  30. add_action( 'woocommerce_after_checkout_form', 'wcpgsk_after_checkout_form', 10, 2 ); 
  31.  
  32. //add_action( 'woocommerce_after_cart_item_quantity_update', 'wcpgsk_after_cart_item_quantity_update', 10, 2 ); 
  33. add_filter( 'woocommerce_add_cart_item', 'wcpgsk_add_cart_item', 10, 2 ); 
  34. add_action( 'woocommerce_check_cart_items', 'wcpgsk_check_cart_items', 10 ); 
  35. add_filter( 'woocommerce_available_variation', 'wcpgsk_available_variation', 10, 3 ); 
  36.  
  37.  
  38.  
  39. //fix input quantity problem of woocommerce for variations as variations are configured via javasript overwriting all filters and actions by woocommerce, in fact a bug of woocommerce 
  40. function wcpgsk_available_variation($variation_data, $product, $variation) { 
  41. $options = get_option( 'wcpgsk_settings' ); 
  42. $ival = apply_filters( 'woocommerce_quantity_input_min', '', $product ); 
  43. if ( !$ival ) : 
  44. $ival = apply_filters( 'woocommerce_quantity_input_step', '1', $product ); 
  45. endif; 
  46. $variation_data['min_qty'] = $ival; 
  47. return $variation_data; 
  48.  
  49. function wcpgsk_check_cart_items() { 
  50. global $woocommerce; 
  51. wcpgsk_clear_messages(); 
  52. //wcpgsk_clear_messages(); 
  53. $options = get_option( 'wcpgsk_settings' ); 
  54. $qtycnt = 0; 
  55. $prodcnt = 0; 
  56. $do_cart_redirect = false; 
  57. foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) : 
  58. $product_id = $values['product_id'];  
  59. $quantity = $values['quantity']; 
  60. $qtycnt += $quantity; 
  61. $prodcnt++; 
  62. $product = get_product( $product_id ); 
  63.  
  64. $minqty = isset($options['cart']['minqty_' . $product->product_type]) && $options['cart']['minqty_' . $product->product_type] ? $options['cart']['minqty_' . $product->product_type] : 0; 
  65. $maxqty = isset($options['cart']['maxqty_' . $product->product_type]) && $options['cart']['maxqty_' . $product->product_type] ? $options['cart']['maxqty_' . $product->product_type] : 0; 
  66. $stepqty = isset($options['cart']['stepqty_' . $product->product_type]) && $options['cart']['stepqty_' . $product->product_type] ? $options['cart']['stepqty_' . $product->product_type] : 0; 
  67. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) :  
  68. $maxval = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  69. if ( isset($maxval) && $maxval > 0 ) : 
  70. $maxqty = $maxval; 
  71. endif; 
  72. $minval = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  73. if ( isset($minval) && $minval > 0 ) : 
  74. $minqty = $minval; 
  75. endif; 
  76. $stepval = get_post_meta($product_id, '_wcpgsk_stepqty', true); 
  77. if ( isset($stepval) && $stepval > 0 ) : 
  78. $stepqty = $stepval; 
  79. endif; 
  80. endif; 
  81. if ( $minqty > 0 && $quantity < $minqty ) : 
  82. $woocommerce->cart->set_quantity( $cart_item_key, $minqty ); 
  83. if ( is_checkout() ) : 
  84. wcpgsk_add_error( sprintf( __( 'You have to buy a minimum quantity. We have set the required minimum of %s as quantity for you.', WCPGSK_DOMAIN ), $minqty ) ); 
  85. $do_cart_redirect = true; 
  86. else : 
  87. wcpgsk_clear_messages(); 
  88. wcpgsk_add_message( sprintf( __( 'You have to buy a minimum quantity. We have set the required minimum of %s as quantity for you.', WCPGSK_DOMAIN ), $minqty ) ); 
  89. endif; 
  90. wcpgsk_set_messages();  
  91. elseif ( $maxqty > 0 && $quantity > $maxqty ) : 
  92. $woocommerce->cart->set_quantity( $cart_item_key, $maxqty ); 
  93. if ( is_checkout() ) : 
  94. wcpgsk_add_error( sprintf( __( 'You cannot buy more than the allowed quantity for this product. We have set the maximum of %s as quantity for you.', WCPGSK_DOMAIN ), $maxqty ) ); 
  95. $do_cart_redirect = true; 
  96. else : 
  97. wcpgsk_clear_messages(); 
  98. wcpgsk_add_message( sprintf( __( 'You cannot buy more than the allowed quantity for this product. We have set the maximum of %s as quantity for you.', WCPGSK_DOMAIN ), $maxqty ) ); 
  99. endif; 
  100. wcpgsk_set_messages();  
  101. elseif ( $stepqty > 0 && ( $quantity % $stepqty ) > 0 ) : 
  102. $remainder = $quantity % $stepqty; 
  103. $newqty = $quantity - $remainder; 
  104. if ( $newqty > 0 ) : 
  105. $woocommerce->cart->set_quantity( $cart_item_key, $newqty ); 
  106. else : 
  107. $newqty = $stepqty; 
  108. $woocommerce->cart->set_quantity( $cart_item_key, $newqty );  
  109. endif; 
  110.  
  111. if ( is_checkout() ) : 
  112. wcpgsk_add_error( sprintf( __( 'You have to buy this product in multiples of %s. We have set the product quantity to the closest lower multiple available.', WCPGSK_DOMAIN ), $stepqty ) ); 
  113. $do_cart_redirect = true; 
  114. else : 
  115. wcpgsk_clear_messages(); 
  116. wcpgsk_add_message( sprintf( __( 'You have to buy this product in multiples of %s. We have set the product quantity to the closest lower multiple available.', WCPGSK_DOMAIN ), $stepqty ) ); 
  117. endif; 
  118. wcpgsk_set_messages();  
  119. endif; 
  120. endforeach; 
  121. $maxqtycart = isset( $options['cart']['maxqtycart'] ) ? $options['cart']['maxqtycart'] : 0; 
  122. $minqtycart = isset( $options['cart']['minqtycart'] ) ? $options['cart']['minqtycart'] : 0; 
  123. if ( $maxqtycart && is_numeric($maxqtycart) && $qtycnt > $maxqtycart ) :  
  124. if ( is_checkout() ) : 
  125. wcpgsk_add_error( sprintf( __( 'The overall sum for all product quantities is restricted to %s in this shop. Your overall quantity sum: %s. Please buy less quantity at least for some products.', WCPGSK_DOMAIN ), $maxqtycart, $qtycnt ) ); 
  126. $do_cart_redirect = true; 
  127. else : 
  128. wcpgsk_clear_messages(); 
  129. wcpgsk_add_message( sprintf( __( 'The overall sum for all product quantities is restricted to %s in this shop. Your overall quantity sum: %s. Please buy less quantity at least for some products.', WCPGSK_DOMAIN ), $maxqtycart, $qtycnt ) ); 
  130. endif; 
  131. wcpgsk_set_messages();  
  132. endif;  
  133. if ( $minqtycart && is_numeric($minqtycart) && $qtycnt < $minqtycart ) :  
  134. if ( is_checkout() ) : 
  135. wcpgsk_add_error( sprintf( __( 'The required minimum sum for all product quantities is set to %s in this shop. Your overall quantity sum: %s. You have to add products to your cart or buy existing products in a higher quantity.', WCPGSK_DOMAIN ), $minqtycart, $qtycnt ) ); 
  136. $do_cart_redirect = true; 
  137. else : 
  138. wcpgsk_clear_messages(); 
  139. wcpgsk_add_message( sprintf( __( 'The required minimum sum for all product quantities is set to %s in this shop. Your overall quantity sum: %s. You have to add products to your cart or buy existing products in a higher quantity.', WCPGSK_DOMAIN ), $minqtycart, $qtycnt ) ); 
  140. endif; 
  141. wcpgsk_set_messages();  
  142. endif;  
  143. if ( $do_cart_redirect ) : 
  144. wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'cart' ) ) );  
  145. endif; 
  146.  
  147. if ( ! function_exists( 'wcpgsk_globalqty_cart_update' ) ) { 
  148. function wcpgsk_globalqty_cart_update( $valid, $cart_item_key, $values, $quantity ) {  
  149. global $woocommerce; 
  150. $options = get_option( 'wcpgsk_settings' ); 
  151. $maxqtycart = isset( $options['cart']['maxqtycart'] ) ? $options['cart']['maxqtycart'] : 0; 
  152. $minqtycart = isset( $options['cart']['minqtycart'] ) ? $options['cart']['minqtycart'] : 0; 
  153. $qtycnt = 0; 
  154. $prodcnt = 0; 
  155. foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) : 
  156. $qtycnt += $values['quantity']; 
  157. $prodcnt++; 
  158. endforeach; 
  159. if ( $maxqtycart && is_numeric($maxqtycart) && $qtycnt > $maxqtycart ) :  
  160. wcpgsk_clear_messages(); 
  161. wcpgsk_add_message( sprintf( __( 'The overall sum for all product quantities is restricted to %s in this shop. Your overall quantity sum: %s. Please buy less quantity at least for some products.', WCPGSK_DOMAIN ), $maxqtycart, $qtycnt ) ); 
  162. wcpgsk_set_messages();  
  163. endif; 
  164. if ( $minqtycart && is_numeric($minqtycart) && $qtycnt < $minqtycart ) :  
  165. wcpgsk_clear_messages(); 
  166. wcpgsk_add_message( sprintf( __( 'The required minimum sum for all product quantities is set to %s in this shop. Your overall quantity sum: %s. You have to add products to your cart or buy existing products in a higher quantity.', WCPGSK_DOMAIN ), $minqtycart, $qtycnt ) ); 
  167. wcpgsk_set_messages();  
  168. endif; 
  169. return $valid; 
  170.  
  171. if ( ! function_exists( 'wcpgsk_globalqty_cart_add' ) ) { 
  172. function wcpgsk_globalqty_cart_add( $valid, $product_id, $quantity ) {  
  173. global $woocommerce; 
  174. //if ( !is_product() ) : 
  175. $options = get_option( 'wcpgsk_settings' ); 
  176. $maxqtycart = isset( $options['cart']['maxqtycart'] ) ? $options['cart']['maxqtycart'] : 0; 
  177. $minqtycart = isset( $options['cart']['minqtycart'] ) ? $options['cart']['minqtycart'] : 0; 
  178. $qtycnt = 0; 
  179. $prodcnt = 0; 
  180. foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) : 
  181. $qtycnt += $values['quantity']; 
  182. $prodcnt++; 
  183. endforeach; 
  184. $qtycnt += $quantity; 
  185. if ( $maxqtycart && is_numeric($maxqtycart) && $qtycnt > $maxqtycart ) :  
  186. wcpgsk_clear_messages(); 
  187. wcpgsk_add_message( sprintf( __( 'The overall sum for all product quantities is restricted to %s in this shop. Your overall quantity sum: %s. Please buy less quantity at least for some products.', WCPGSK_DOMAIN ), $maxqtycart, $qtycnt ) ); 
  188. wcpgsk_set_messages();  
  189. endif; 
  190. if ( $minqtycart && is_numeric($minqtycart) && $qtycnt < $minqtycart ) :  
  191. wcpgsk_clear_messages(); 
  192. wcpgsk_add_message( sprintf( __( 'The required minimum sum for all product quantities is set to %s in this shop. Your overall quantity sum: %s. You have to add products to your cart or buy existing products in a higher quantity.', WCPGSK_DOMAIN ), $minqtycart, $qtycnt ) ); 
  193. wcpgsk_set_messages();  
  194. endif; 
  195. //endif; 
  196. return $valid; 
  197.  
  198. if ( !function_exists('wcpgsk_add_cart_item') ) { 
  199. function wcpgsk_add_cart_item( $cart_item_data, $cart_item_key ) { 
  200. global $woocommerce; 
  201. $options = get_option( 'wcpgsk_settings' ); 
  202.  
  203. $product_id = $cart_item_data['product_id']; 
  204. $variation_id = $cart_item_data['variation_id']; 
  205. $product = get_product($product_id); 
  206. $quantity = $cart_item_data['quantity']; 
  207.  
  208. $maxqty = isset($options['cart']['maxqty_' . $product->product_type]) ? $options['cart']['maxqty_' . $product->product_type] : 0; 
  209. $minqty = isset($options['cart']['minqty_' . $product->product_type]) ? $options['cart']['minqty_' . $product->product_type] : 0; 
  210. $stepqty = isset($options['cart']['stepqty_' . $product->product_type]) ? $options['cart']['stepqty_' . $product->product_type] : 0; 
  211.  
  212. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  213. $maxval = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  214. if ( isset($maxval) && $maxval > 0 ) : 
  215. $maxqty = $maxval; 
  216. endif; 
  217. $minval = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  218. if ( isset($minval) && $minval > 0 ) : 
  219. $minqty = $minval; 
  220. endif; 
  221. $stepval = get_post_meta($product_id, '_wcpgsk_stepqty', true); 
  222. if ( isset($stepval) && $stepval > 0 ) : 
  223. $stepqty = $stepval; 
  224. endif; 
  225. endif; 
  226.  
  227. if ($minqty > 0 && $quantity < $minqty) : 
  228. $cart_item_data['quantity'] = $minqty; 
  229. wcpgsk_clear_messages(); 
  230. wcpgsk_add_message( sprintf( __( 'You have to buy a minimum quantity. We have set the required minimum of %s as quantity for you.', WCPGSK_DOMAIN ), $minqty ) ); 
  231. wcpgsk_set_messages();  
  232. elseif ($maxqty > 0 && $quantity > $maxqty) : 
  233. $cart_item_data['quantity'] = $maxqty; 
  234. wcpgsk_clear_messages(); 
  235. wcpgsk_add_message( sprintf(__( 'You cannot buy more than the allowed maximum quantity. We have set the allowed maximum of %s as quantity for you.', WCPGSK_DOMAIN ), $maxqty ) ); 
  236. wcpgsk_set_messages(); 
  237. elseif ( $stepqty > 0 && ( $quantity % $stepqty ) > 0 ) : 
  238. $remainder = $quantity % $stepqty; 
  239. $newqty = $quantity - $remainder; 
  240. if ( $newqty > 0 ) : 
  241. $cart_item_data['quantity'] = $newqty; 
  242. else : 
  243. $newqty = $stepqty; 
  244. $cart_item_data['quantity'] = $newqty; 
  245. endif;  
  246. wcpgsk_clear_messages(); 
  247. wcpgsk_add_message( sprintf( __( 'You have to buy this product in multiples of %s. We have set the product quantity to the closest lower multiple available.', WCPGSK_DOMAIN ), $stepqty ) ); 
  248. wcpgsk_set_messages();  
  249. endif; 
  250. return $cart_item_data; 
  251.  
  252. if ( !function_exists('wcpgsk_after_cart_item_quantity_update') ) { 
  253. function wcpgsk_after_cart_item_quantity_update( $cart_item_key, $quantity ) { 
  254. global $woocommerce; 
  255. $options = get_option( 'wcpgsk_settings' ); 
  256. $product_id = $woocommerce->cart->cart_contents[$cart_item_key]['product_id']; 
  257. $variation_id = $woocommerce->cart->cart_contents[$cart_item_key]['variation_id']; 
  258. $product = get_product($product_id); 
  259.  
  260. $maxqty = isset($options['cart']['maxqty_' . $product->product_type]) ? $options['cart']['maxqty_' . $product->product_type] : 0; 
  261. $minqty = isset($options['cart']['minqty_' . $product->product_type]) ? $options['cart']['minqty_' . $product->product_type] : 0; 
  262. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  263. $product_id = $product->ID;  
  264. $maxval = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  265. $minval = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  266. if ( isset($maxval) && $maxval > 0 ) : 
  267. $maxqty = $maxval; 
  268. endif; 
  269. if ( isset($minval) && $minval > 0 ) : 
  270. $minqty = $minval; 
  271. endif; 
  272. endif; 
  273.  
  274.  
  275. if ($minqty > 0 && $quantity < $minqty) : 
  276. $woocommerce->cart->cart_contents[$cart_item_key]['quantity'] = $minqty; 
  277. wcpgsk_add_message( sprintf( __( 'You have to buy a minimum quantity. We have set the required minimum of %s as quantity for you.', WCPGSK_DOMAIN ), $minqty ) ); 
  278. wcpgsk_set_messages(); 
  279.  
  280. elseif ($maxqty > 0 && $quantity > $maxqty) : 
  281. $woocommerce->cart->cart_contents[$cart_item_key]['quantity'] = $maxqty; 
  282. wcpgsk_add_message( sprintf(__( 'You cannot buy more than the allowed maximum quantity. We have set the allowed maximum of %s as quantity for you.', WCPGSK_DOMAIN ), $maxqty ) ); 
  283. wcpgsk_set_messages(); 
  284. endif; 
  285.  
  286.  
  287. if ( !function_exists('wcpgsk_maxitems_in_cart') ) { 
  288. function wcpgsk_maxitems_in_cart( $valid, $product_id, $quantity ) { 
  289. global $woocommerce; 
  290. $options = get_option( 'wcpgsk_settings' ); 
  291.  
  292. $cartItems = sizeof( $woocommerce->cart->cart_contents ); 
  293. $allowed = isset($options['cart']['maxitemscart']) && $options['cart']['maxitemscart'] != 0 ? $options['cart']['maxitemscart'] : 0; 
  294.  
  295. //check cart items count and diminish if more than one variation for a product exists 
  296. if ( $allowed > 0 && isset($options['cart']['variationscountasproduct']) && $options['cart']['variationscountasproduct'] == 0) {  
  297. $varproducts = array(); 
  298. foreach($woocommerce->cart->cart_contents as $i => $values) { 
  299. $key = $values['product_id']; 
  300. //@TODO: Check layout of the question and answer 
  301. if (isset($values[$key]) && isset($values['variation_id']) && $values[$key] != $values['variation_id']) { 
  302. if (isset($varproducts[$key])) $varproducts[$key] = 1; 
  303. else $varproducts[$key] = 0; 
  304. if (!empty($varproducts)) $cartItems = $cartItems - array_sum($varproducts); 
  305.  
  306. if ( $allowed > 0 && $cartItems >= $allowed ) { 
  307. // Sets error message. 
  308. wcpgsk_add_message( sprintf( __( 'You have reached the maximum amount of %s items allowed for your cart!', WCPGSK_DOMAIN ), $allowed ) ); 
  309. wcpgsk_set_messages(); 
  310. $valid = false; 
  311. $cart_url = $woocommerce->cart->get_cart_url(); 
  312. wcpgsk_add_message( __('Remove products from the cart', WCPGSK_DOMAIN) . ': <a href="' . $cart_url . '">' . __('Cart', WCPGSK_DOMAIN) . '</a>'); 
  313. wcpgsk_set_messages(); 
  314. }  
  315. return $valid; 
  316.  
  317.  
  318. if ( !function_exists('wcpgsk_minitems_in_cart') ) { 
  319. /** 
  320. * Validate product quantity on cart update. 
  321. */ 
  322. function wcpgsk_minitems_in_cart( $valid, $cart_item_key, $values, $quantity ) { 
  323. global $woocommerce; 
  324. $options = get_option( 'wcpgsk_settings' ); 
  325.  
  326. //$cartItems = $woocommerce->cart->get_cart_contents_count(); //counts quantities as well and not only items 
  327. $cartItems = sizeof( $woocommerce->cart->cart_contents ); 
  328. $allowed = isset($options['cart']['minitemscart']) && $options['cart']['minitemscart'] != 0 ? $options['cart']['minitemscart'] : 0; 
  329.  
  330. //check cart items count and diminish if more than one variation for a product exists 
  331. if ($allowed > 1 && isset($options['cart']['variationscountasproduct']) && $options['cart']['variationscountasproduct'] == 0) {  
  332. $varproducts = array(); 
  333. foreach($woocommerce->cart->cart_contents as $i => $values) { 
  334. $key = $values['product_id']; 
  335. //@TODO: Check layout of the question and answer  
  336. if (isset($values[$key]) && isset($values['variation_id']) && $values[$key] != $values['variation_id']) { 
  337. if (isset($varproducts[$key])) $varproducts[$key] = 1; 
  338. else $varproducts[$key] = 0; 
  339. if (!empty($varproducts)) $cartItems = $cartItems - array_sum($varproducts); 
  340.  
  341. if ($allowed > 1 && $allowed > $cartItems ) { 
  342. // Sets error message. 
  343. wcpgsk_add_message( sprintf( __( 'You still have not reached the minimum amount of %s items required for your cart!', WCPGSK_DOMAIN ), $allowed ) ); 
  344. wcpgsk_set_messages(); 
  345. $valid = false; 
  346.  
  347. $shop_page_id = woocommerce_get_page_id( 'shop' ); 
  348. //$shop_page_url = get_permalink(icl_object_id($shop_page_id, 'page', false)); 
  349. $shop_page_url = get_permalink($shop_page_id); 
  350. wcpgsk_add_message( __('Select more products from the shop', WCPGSK_DOMAIN) . ': <a href="' . $shop_page_url . '">' . __('Shop', WCPGSK_DOMAIN) . '</a>'); 
  351. wcpgsk_set_messages(); 
  352.  
  353. }  
  354. return $valid; 
  355.  
  356. if ( !function_exists('wcpgsk_check_qty_config') ) { 
  357. /** 
  358. * @changed 1.8.1 to fix sold_individually problem 
  359. */ 
  360. function wcpgsk_check_qty_config( $return, $product ) { 
  361. global $woocommerce; 
  362. $options = get_option( 'wcpgsk_settings' ); 
  363. //respect established will fix bug communicated 
  364. $switch = $return; 
  365.  
  366. switch ($product->product_type) { 
  367. case 'variation' : 
  368. if( isset($options['cart']['variationproductnoqty']) && $options['cart']['variationproductnoqty'] == 1) 
  369. $switch = true; 
  370. break; 
  371. case 'variable' : 
  372. if(isset($options['cart']['variableproductnoqty']) && $options['cart']['variableproductnoqty'] == 1) 
  373. $switch = true; 
  374. break; 
  375. case 'external' : 
  376. if( isset($options['cart']['externalproductnoqty']) && $options['cart']['externalproductnoqty'] == 1) 
  377. $switch = true; 
  378. break; 
  379. default : 
  380. if( isset($options['cart']['simpleproductnoqty']) && $options['cart']['simpleproductnoqty'] == 1) 
  381. $switch = true; 
  382. break; 
  383. return $switch; 
  384.  
  385. if ( !function_exists('wcpgsk_qtyselector_max') ) { 
  386. function wcpgsk_qtyselector_max( $whatever, $product = null ) { 
  387. if ( isset( $product ) && is_object( $product ) ) : 
  388. global $wcpgsk_session; 
  389. $options = get_option( 'wcpgsk_settings' );  
  390. if ( $product->is_sold_individually() ) : 
  391. $maxqty = 1; 
  392. else : 
  393. $maxqty = isset($options['cart']['maxqty_' . $product->product_type]) && $options['cart']['maxqty_' . $product->product_type] != 0 ? $options['cart']['maxqty_' . $product->product_type] : '';  
  394. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  395. $product_id = $product->post->ID;  
  396. $maxval = get_post_meta($product_id, '_wcpgsk_maxqty', true); 
  397. if ( isset($maxval) && $maxval > 0 ) : 
  398. $maxqty = $maxval; 
  399. endif; 
  400. endif; 
  401. if ($maxqty == '' && isset($wcpgsk_session->qtyargs['max_value']) ) { 
  402. $maxqty = $wcpgsk_session->qtyargs['max_value']; 
  403. endif; 
  404. return $maxqty; 
  405. else : 
  406. return $whatever; 
  407. endif; 
  408.  
  409. if ( !function_exists('wcpgsk_qtyselector_min') ) { 
  410. function wcpgsk_qtyselector_min( $whatever, $product = null ) { 
  411. if ( isset( $product ) && is_object( $product ) ) : 
  412. global $wcpgsk_session; 
  413. $options = get_option( 'wcpgsk_settings' ); 
  414. if ( $product->is_sold_individually() ) : 
  415. $minqty = 1; 
  416. else : 
  417. $minqty = isset($options['cart']['minqty_' . $product->product_type]) && $options['cart']['minqty_' . $product->product_type] != 0 ? $options['cart']['minqty_' . $product->product_type] : 0; 
  418. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  419. $product_id = $product->post->ID;  
  420. $minval = get_post_meta($product_id, '_wcpgsk_minqty', true); 
  421. if ( isset($minval) && $minval > 0 ) : 
  422. $minqty = $minval; 
  423. endif; 
  424. endif; 
  425. if ($minqty == '' && isset($wcpgsk_session->qtyargs['min_value']) ) { 
  426. $minqty = $wcpgsk_session->qtyargs['min_value']; 
  427. endif; 
  428. return $minqty; 
  429. else : 
  430. return $whatever; 
  431. endif; 
  432.  
  433. if ( !function_exists('wcpgsk_quantity_input_step') ) { 
  434. function wcpgsk_quantity_input_step( $whatever, $product = null ) { 
  435. if ( isset( $product ) && is_object( $product ) ) : 
  436. global $wcpgsk_session; 
  437. $options = get_option( 'wcpgsk_settings' ); 
  438. if ( $product->is_sold_individually() ) : 
  439. $stepqty = 1; 
  440. else :  
  441. $stepqty = isset($options['cart']['stepqty_' . $product->product_type]) && $options['cart']['stepqty_' . $product->product_type] != 0 ? $options['cart']['stepqty_' . $product->product_type] : 1; 
  442. if ( isset($options['cart']['minmaxstepproduct']) && $options['cart']['minmaxstepproduct'] == 1 ) : 
  443. $product_id = $product->post->ID;  
  444. $stepval = get_post_meta($product_id, '_wcpgsk_stepqty', true); 
  445. if ( isset($stepval) && $stepval > 0 ) : 
  446. $stepqty = $stepval; 
  447. endif; 
  448. endif; 
  449. endif; 
  450. return $stepqty; 
  451. else : 
  452. return $whatever; 
  453. endif; 
  454.  
  455. if ( !function_exists('wcpgsk_qty_input_args') ) { 
  456. /** 
  457. * @changed 1.5.4 to avoid warnings in some php contexts 
  458. * @TODO: revision of this all as the whole process is not meaningful due to some other changes 
  459. */ 
  460. function wcpgsk_qty_input_args($argss) { 
  461. global $wcpgsk_session, $woocommerce; 
  462.  
  463. if ( !isset($wcpgsk_session) ) : 
  464. $wcpgsk_session = $woocommerce->session; 
  465. endif; 
  466. if ( isset($wcpgsk_session) && isset($args) && !empty($args) ) :  
  467. $wcpgsk_session->qtyargs = $args; 
  468. endif; 
  469. return $args; 
  470.  
  471. /** 
  472. * Redirect to fast checkout 
  473. */ 
  474. if ( !function_exists('wcpgsk_add_to_checkout_redirect') ) { 
  475. function wcpgsk_add_to_checkout_redirect() {  
  476. return get_permalink( woocommerce_get_page_id( 'checkout' ) ); 
  477. /** 
  478. * Redirect to cart 
  479. */ 
  480. if ( !function_exists('wcpgsk_add_to_cart_redirect') ) { 
  481. function wcpgsk_add_to_cart_redirect() {  
  482. return get_permalink( woocommerce_get_page_id( 'cart' ) ); 
  483.  
  484.  
  485. if ( isset($wcpgsk_options['process']['fastcart']) && $wcpgsk_options['process']['fastcart'] == 1 && $wcpgsk_options['process']['fastcheckout'] == 0) { 
  486. update_option('woocommerce_cart_redirect_after_add', 'yes'); 
  487. //update_option('woocommerce_enable_ajax_add_to_cart', 'no'); 
  488. elseif ( isset($wcpgsk_options['process']['fastcheckout']) && $wcpgsk_options['process']['fastcheckout'] == 1 && $wcpgsk_options['process']['fastcart'] == 0) { 
  489. update_option('woocommerce_cart_redirect_after_add', 'no'); 
  490. //update_option('woocommerce_enable_ajax_add_to_cart', 'no'); //@TODO: check if this option is correct like this 
  491. add_filter('add_to_cart_redirect', 'wcpgsk_add_to_checkout_redirect', 99); //late execution, to assure that we overwrite WooCommerce Setting 
  492.  
  493.  
  494. if ( !function_exists('wcpgsk_cart_button_text') ) { 
  495. /** 
  496. * Personalize Add to Cart Button 
  497. */ 
  498. function wcpgsk_cart_button_text($label) { 
  499. global $post; 
  500.  
  501. $options = get_option( 'wcpgsk_settings' ); 
  502. $cart_btn_text = ((!empty($options['process']['fastcheckoutbtn'])) ? __($options['process']['fastcheckoutbtn'], WCPGSK_DOMAIN) : $label); 
  503. if ( isset( $post->ID ) && ( is_shop() || is_product() ) ) : 
  504. $button_label = get_post_meta($post->ID, '_wcpgsk_button_label', true); 
  505. if ( isset( $button_label ) && !empty( $button_label ) ) : 
  506. $cart_btn_text = "hoopie";//__( $button_label, WCPGSK_DOMAIN ); 
  507. endif; 
  508. endif; 
  509. if ($cart_btn_text && $cart_btn_text != '') 
  510. return $cart_btn_text; 
  511. else return __('Add to Cart', WCPGSK_DOMAIN); 
  512.  
  513. if ( !function_exists('wcpgsk_grouped_cart_button_text') ) { 
  514. /** 
  515. * Personalize Add to Cart Button 
  516. */ 
  517. function wcpgsk_grouped_cart_button_text($label) { 
  518. $options = get_option( 'wcpgsk_settings' ); 
  519. $cart_btn_text = ((!empty($options['process']['viewproductsbtn'])) ? __($options['process']['viewproductsbtn'], WCPGSK_DOMAIN) : $label); 
  520. if ($cart_btn_text && $cart_btn_text != '') 
  521. return $cart_btn_text; 
  522. else return __('View options', WCPGSK_DOMAIN); 
  523.  
  524. if ( !function_exists('wcpgsk_variable_cart_button_text') ) { 
  525. /** 
  526. * Personalize Add to Cart Button 
  527. */ 
  528. function wcpgsk_variable_cart_button_text($label) { 
  529. $options = get_option( 'wcpgsk_settings' ); 
  530. $cart_btn_text = ((!empty($options['process']['selectoptionsbtn'])) ? __($options['process']['selectoptionsbtn'], WCPGSK_DOMAIN) : $label); 
  531. if ($cart_btn_text && $cart_btn_text != '') 
  532. return $cart_btn_text; 
  533. else return __('Select options', WCPGSK_DOMAIN); 
  534.  
  535. if ( !function_exists('wcpgsk_external_cart_button_text') ) { 
  536. /** 
  537. * Personalize Add to Cart Button 
  538. */ 
  539. function wcpgsk_external_cart_button_text($label) { 
  540. $options = get_option( 'wcpgsk_settings' ); 
  541. $cart_btn_text = ((!empty($options['process']['readmorebtn'])) ? __($options['process']['readmorebtn'], WCPGSK_DOMAIN) : $label); 
  542. if ($cart_btn_text && $cart_btn_text != '') 
  543. return $cart_btn_text; 
  544. else return __('Read more', WCPGSK_DOMAIN); 
  545.  
  546. if ( !function_exists('wcpgsk_outofstock_cart_button_text') ) { 
  547. /** 
  548. * Personalize Add to Cart Button 
  549. */ 
  550. function wcpgsk_outofstock_cart_button_text($label) { 
  551. $options = get_option( 'wcpgsk_settings' ); 
  552. $cart_btn_text = ((!empty($options['process']['outofstockbtn'])) ? __($options['process']['outofstockbtn'], WCPGSK_DOMAIN) : $label); 
  553. if ($cart_btn_text && $cart_btn_text != '') 
  554. return $cart_btn_text; 
  555. else return __('Read more', WCPGSK_DOMAIN); 
  556.  
  557. if ( !function_exists('wcpgsk_single_cart_button_text') ) { 
  558. function wcpgsk_single_cart_button_text($label, $ptype) { 
  559. global $post;  
  560. $options = get_option( 'wcpgsk_settings' ); 
  561. $cart_btn_text = ((!empty($options['process']['fastcheckoutbtn'])) ? __($options['process']['fastcheckoutbtn'], WCPGSK_DOMAIN) : 'Add to Cart'); 
  562. if ( isset( $post->ID ) && ( is_shop() || is_product() ) ) : 
  563. $button_label = get_post_meta($post->ID, '_wcpgsk_button_label', true); 
  564. if ( isset( $button_label ) && !empty( $button_label ) ) : 
  565. $cart_btn_text = "hoopie";//__( $button_label, WCPGSK_DOMAIN ); 
  566. endif; 
  567. endif; 
  568.  
  569. if ($cart_btn_text && $cart_btn_text != '') 
  570. return $cart_btn_text; 
  571. else return __('Add to Cart', WCPGSK_DOMAIN); 
  572.  
  573. /** 
  574. * Personalize Add to Cart Button 
  575. */ 
  576. if ( !function_exists('wcpgsk_product_single_cart_button_text') ) { 
  577. function wcpgsk_product_single_cart_button_text($label, $product) { 
  578. $options = get_option( 'wcpgsk_settings' ); 
  579. $cart_btn_text = $label; 
  580. if ( $label == __( 'Read more', 'woocommerce' ) ) : 
  581. $cart_btn_text = ((!empty($options['process']['readmorebtn'])) ? __($options['process']['readmorebtn'], WCPGSK_DOMAIN) : $label); 
  582. elseif ($label == __( 'Add to cart', 'woocommerce' ) ) : 
  583. $cart_btn_text = ((!empty($options['process']['fastcheckoutbtn'])) ? __($options['process']['fastcheckoutbtn'], WCPGSK_DOMAIN) : $label); 
  584. if ( isset( $product->post->ID ) && ( is_shop() || is_product() ) ) : 
  585. $button_label = get_post_meta($product->post->ID, '_wcpgsk_button_label', true); 
  586. if ( isset( $button_label ) && !empty( $button_label ) ) : 
  587. $cart_btn_text = __( $button_label, WCPGSK_DOMAIN ); 
  588. endif; 
  589. endif;  
  590. elseif ($label == __( 'Buy product', 'woocommerce' ) ) : 
  591. $cart_btn_text = ((!empty($options['process']['buyproductbtn'])) ? __($options['process']['buyproductbtn'], WCPGSK_DOMAIN) : $label); 
  592. elseif ($label == __( 'View products', 'woocommerce' ) ) : 
  593. $cart_btn_text = ((!empty($options['process']['viewproductsbtn'])) ? __($options['process']['viewproductsbtn'], WCPGSK_DOMAIN) : $label); 
  594. elseif ($label == __( 'Select options', 'woocommerce' ) ) : 
  595. $cart_btn_text = ((!empty($options['process']['selectoptionsbtn'])) ? __($options['process']['selectoptionsbtn'], WCPGSK_DOMAIN) : $label); 
  596. endif; 
  597.  
  598. return $cart_btn_text; 
  599.  
  600. if ( !function_exists('wcpgsk_product_cart_button_text') ) { 
  601. function wcpgsk_product_cart_button_text($label, $product) { 
  602. $options = get_option( 'wcpgsk_settings' ); 
  603. $cart_btn_text = $label; 
  604. if ( $label == __( 'Read more', 'woocommerce' ) ) : 
  605. $cart_btn_text = ((!empty($options['process']['readmorebtn'])) ? __($options['process']['readmorebtn'], WCPGSK_DOMAIN) : $label); 
  606. elseif ($label == __( 'Add to cart', 'woocommerce' ) ) : 
  607. $cart_btn_text = ((!empty($options['process']['fastcheckoutbtn'])) ? __($options['process']['fastcheckoutbtn'], WCPGSK_DOMAIN) : $label); 
  608. if ( isset( $product->post->ID ) && ( is_shop() || is_product() ) ) : 
  609. $button_label = get_post_meta($product->post->ID, '_wcpgsk_button_label', true); 
  610. if ( isset( $button_label ) && !empty( $button_label ) ) : 
  611. $cart_btn_text = __( $button_label, WCPGSK_DOMAIN ); 
  612. endif; 
  613. endif;  
  614. elseif ($label == __( 'Buy product', 'woocommerce' ) ) : 
  615. $cart_btn_text = ((!empty($options['process']['buyproductbtn'])) ? __($options['process']['buyproductbtn'], WCPGSK_DOMAIN) : $label); 
  616. if ( isset( $product->post->ID ) && ( is_shop() || is_product() ) ) : 
  617. $button_label = get_post_meta($product->post->ID, '_wcpgsk_button_label', true); 
  618. if ( isset( $button_label ) && !empty( $button_label ) ) : 
  619. $cart_btn_text = __( $button_label, WCPGSK_DOMAIN ); 
  620. endif; 
  621. endif;  
  622. elseif ($label == __( 'View products', 'woocommerce' ) ) : 
  623. $cart_btn_text = ((!empty($options['process']['viewproductsbtn'])) ? __($options['process']['viewproductsbtn'], WCPGSK_DOMAIN) : $label); 
  624. elseif ($label == __( 'Select options', 'woocommerce' ) ) : 
  625. $cart_btn_text = ((!empty($options['process']['selectoptionsbtn'])) ? __($options['process']['selectoptionsbtn'], WCPGSK_DOMAIN) : $label); 
  626. endif; 
  627.  
  628. return $cart_btn_text; 
  629.  
  630. //Payment gateways 
  631. $wcpgsk_options = get_option('wcpgsk_settings'); 
  632. if ( isset($wcpgsk_options['process']['paymentgateways']) && 1 == ($wcpgsk_options['process']['paymentgateways'])) : 
  633. require_once ABSPATH . WPINC . '/pluggable.php';; 
  634. if ( function_exists('WC') ) : 
  635. require_once dirname(dirname(__FILE__)).'/woocommerce/includes/class-wc-payment-gateways.php'; 
  636. require_once dirname(dirname(__FILE__)).'/woocommerce/includes/class-wc-cart.php'; 
  637. else : 
  638. require_once dirname(dirname(__FILE__)).'/woocommerce/classes/class-wc-payment-gateways.php'; 
  639. require_once dirname(dirname(__FILE__)).'/woocommerce/classes/class-wc-cart.php'; 
  640. endif;  
  641.  
  642. add_action( 'add_meta_boxes', 'wcpgsk_gateways_meta_box_add' );  
  643. if ( !function_exists('wcpgsk_gateways_meta_box_add') ) { 
  644. function wcpgsk_gateways_meta_box_add()  
  645. {  
  646. add_meta_box( 'payments', 'Payment Gateways', 'wcpgsk_payments_form', 'product', 'side', 'core' );  
  647. if ( !function_exists('wcpgsk_payments_form') ) { 
  648. function wcpgsk_payments_form()  
  649. global $post;//, $woo; 
  650. $postPayments = get_metadata('post', $post->ID, 'payment_gateways', false) ; 
  651. $woogate = new WC_Payment_Gateways(); 
  652.  
  653. $payments = $woogate->payment_gateways();//get_available_payment_gateways(); 
  654.  
  655. foreach ($payments as $pay) { 
  656. $checked = ''; 
  657.  
  658. if ( in_array($pay->id, $postPayments) ) $checked = ' checked="yes" '; 
  659. ?>  
  660. <input type="checkbox" <?php echo $checked; ?> value="<?php echo $pay->id; ?>" name="pays[]" id="payments" /> 
  661. <label for="payment_gateway_meta_box_text"><?php echo $pay->title; ?></label>  
  662. <br />  
  663. <?php  
  664. }  
  665.  
  666. }  
  667. add_action('save_post', 'wcpgsk_gateways_meta_box_save', 10, 2 ); 
  668. if ( !function_exists('wcpgsk_gateways_meta_box_save') ) { 
  669. function wcpgsk_gateways_meta_box_save( $post_id )  
  670. {  
  671. if(isset($_POST['post_type']) && $_POST['post_type']=='product') : 
  672. delete_post_meta($post_id, 'payment_gateways');  
  673. if( isset( $_POST['pays'] ) && $_POST['pays']) : 
  674. foreach($_POST['pays'] as $pay) : 
  675. add_post_meta($post_id, 'payment_gateways', $pay);  
  676. endforeach; 
  677. endif; 
  678.  
  679. endif; 
  680. if ( !function_exists('wcpgsk_restrict_payment_gateways') ) { 
  681. function wcpgsk_restrict_payment_gateways( $restrict_gateways ) { 
  682. global $woocommerce; 
  683. $arrayKeys = array_keys($restrict_gateways); 
  684. $items = isset($woocommerce->cart->cart_contents) ? $woocommerce->cart->cart_contents : array(); 
  685. $itemGateways = ''; 
  686. if($items) 
  687. foreach($items as $item) 
  688. $itemGateways[] = get_metadata('post', $item['product_id'], 'payment_gateways', false) ; 
  689. if($itemGateways) 
  690. foreach($itemGateways as $gateway) 
  691. if(count($gateway)) : 
  692. foreach($arrayKeys as $key) : 
  693. if(!in_array($key, $gateway)) : 
  694. unset($restrict_gateways[$key]); 
  695. endif; 
  696. endforeach; 
  697. endif; 
  698. return $restrict_gateways; 
  699. add_filter( 'woocommerce_available_payment_gateways', 'wcpgsk_restrict_payment_gateways' ); 
  700. endif; 
  701.  
  702. if ( !function_exists('wcpgsk_after_checkout_form') ) { 
  703. function wcpgsk_after_checkout_form($checkout) { 
  704. if ( is_checkout() || is_account_page() ) : 
  705. ?> 
  706. <div id="wcpgsk-dialog-validation-errors" title="<?php _e('Validation errors' , WCPGSK_DOMAIN); ?>"> 
  707. <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span><?php _e('Please check the fields marked with a red border. The values do not pass validation.' , WCPGSK_DOMAIN); ?></p>  
  708. </div> 
  709. <?php 
  710. $options = get_option( 'wcpgsk_settings' ); 
  711.  
  712.  
  713. echo '<script language="javascript">'; 
  714.  
  715. echo 'jQuery(document).ready(function() { 
  716. var cT = "' . __('Close', WCPGSK_DOMAIN) . '"; 
  717. var pT = "' . __('<Prev', WCPGSK_DOMAIN) . '"; 
  718. var nT = "' . __('Next>', WCPGSK_DOMAIN) . '"; 
  719. var cTT = "' . __('Now', WCPGSK_DOMAIN) . '"; 
  720. var cTD = "' . __('Today', WCPGSK_DOMAIN) . '"; 
  721.  
  722. var mN = ["' . __('January', WCPGSK_DOMAIN) . '",  
  723. "' . __('February', WCPGSK_DOMAIN) . '",  
  724. "' . __('March', WCPGSK_DOMAIN) . '",  
  725. "' . __('April', WCPGSK_DOMAIN) . '",  
  726. "' . __('May', WCPGSK_DOMAIN) . '",  
  727. "' . __('June', WCPGSK_DOMAIN) . '",  
  728. "' . __('July', WCPGSK_DOMAIN) . '",  
  729. "' . __('August', WCPGSK_DOMAIN) . '",  
  730. "' . __('September', WCPGSK_DOMAIN) . '",  
  731. "' . __('October', WCPGSK_DOMAIN) . '",  
  732. "' . __('November', WCPGSK_DOMAIN) . '",  
  733. "' . __('December', WCPGSK_DOMAIN) . '"]; 
  734.  
  735. var mNS = ["' . __('Jan', WCPGSK_DOMAIN) . '",  
  736. "' . __('Feb', WCPGSK_DOMAIN) . '",  
  737. "' . __('Mar', WCPGSK_DOMAIN) . '",  
  738. "' . __('Apr', WCPGSK_DOMAIN) . '",  
  739. "' . __('May', WCPGSK_DOMAIN) . '",  
  740. "' . __('Jun', WCPGSK_DOMAIN) . '",  
  741. "' . __('Jul', WCPGSK_DOMAIN) . '",  
  742. "' . __('Aug', WCPGSK_DOMAIN) . '",  
  743. "' . __('Sep', WCPGSK_DOMAIN) . '",  
  744. "' . __('Oct', WCPGSK_DOMAIN) . '",  
  745. "' . __('Nov', WCPGSK_DOMAIN) . '",  
  746. "' . __('Dec', WCPGSK_DOMAIN) . '"]; 
  747.  
  748. var dN = ["' . __('Sunday', WCPGSK_DOMAIN) . '",  
  749. "' . __('Monday', WCPGSK_DOMAIN) . '",  
  750. "' . __('Tuesday', WCPGSK_DOMAIN) . '",  
  751. "' . __('Wednesday', WCPGSK_DOMAIN) . '",  
  752. "' . __('Thursday', WCPGSK_DOMAIN) . '",  
  753. "' . __('Friday', WCPGSK_DOMAIN) . '",  
  754. "' . __('Saturday', WCPGSK_DOMAIN) . '"]; 
  755.  
  756. var dNS = ["' . __('Sun', WCPGSK_DOMAIN) . '",  
  757. "' . __('Mon', WCPGSK_DOMAIN) . '",  
  758. "' . __('Tue', WCPGSK_DOMAIN) . '",  
  759. "' . __('Wed', WCPGSK_DOMAIN) . '",  
  760. "' . __('Thu', WCPGSK_DOMAIN) . '",  
  761. "' . __('Fri', WCPGSK_DOMAIN) . '",  
  762. "' . __('Sat', WCPGSK_DOMAIN) . '"]; 
  763.  
  764.  
  765.  
  766. jQuery("input[display=\'date\']").each(function(i, cal) { 
  767. var minD = "' . $options['checkoutform']['mindate'] . '"; 
  768. var maxD = "' . $options['checkoutform']['maxdate'] . '"; 
  769. if (jQuery(this).attr("mindays")) minD = jQuery(this).attr("mindays"); 
  770. if (jQuery(this).attr("maxdays")) maxD = jQuery(this).attr("maxdays"); 
  771.  
  772. var dateF = "yy/mm/dd"; 
  773. if (jQuery(this).attr("dateformat") && jQuery(this).attr("dateformat") != null && jQuery(this).attr("dateformat") != "") dateF = jQuery(this).attr("dateformat"); 
  774. var exDays = ""; 
  775. var exDates = ""; 
  776. var exWeekend = "0"; 
  777. if (jQuery(this).attr("daysexcluded")) exDays = jQuery(this).attr("daysexcluded"); 
  778. if (jQuery(this).attr("datesexcluded")) exDates = jQuery(this).attr("datesexcluded"); 
  779. if (jQuery(this).attr("exweekend")) exWeekend = jQuery(this).attr("exweekend"); 
  780.  
  781. jQuery(this).prop("readonly", "readonly"); 
  782.  
  783. if ( exDays != null && exDays != "" ) exDays = jQuery.map(exDays.split(", "), jQuery.trim);  
  784. if ( exDates != null && exDates != "" ) exDates = jQuery.map(exDates.split(", "), jQuery.trim); 
  785. jQuery(this).datepicker({ 
  786. changeMonth: true,  
  787. changeYear: true,  
  788. yearRange: "-100:+100",  
  789. beforeShow: function() { 
  790. },  
  791. beforeShowDay: function(date) { 
  792. show = true; 
  793. if ( exWeekend == "1" ) { 
  794. show = jQuery.datepicker.noWeekends(date)[0]; 
  795. if ( show && exDays != null && exDays != "" && exDays.length > 0 ) { 
  796.  
  797. if ( jQuery.inArray( date.getDay().toString(), exDays ) !== -1 ) show = false; 
  798. if ( show && exDates != null && exDates != "" && exDates.length > 0 ) {  
  799. checkDate = jQuery.datepicker.formatDate(dateF, date); 
  800. if ( jQuery.inArray( checkDate.toString(), exDates ) !== -1 ) show = false; 
  801. return [show, "", (!show) ? "' . __('Date excluded', WCPGSK_DOMAIN) . '" : ""]; 
  802. },  
  803. dateFormat: dateF,  
  804. minDate: minD,  
  805. maxDate: maxD,  
  806. dayNamesShort: dNS,  
  807. dayNames: dN,  
  808. monthNamesShort: mNS,  
  809. monthNames: mN,  
  810. closeText: cT,  
  811. prevText: pT,  
  812. nextText: nT,  
  813. currentText: cTD,  
  814. firstDay: 1 
  815. });  
  816. }); 
  817. '; 
  818. if ( isset( $options['checkoutform']['caltimepicker'] ) && 1 == $options['checkoutform']['caltimepicker'] ) : 
  819. echo ' jQuery("input[display=\'time\']").each(function() { 
  820. var hMax = 23; 
  821. var hMin = 0;  
  822. if (jQuery(this).attr("maxhour")) hMax = parseInt(jQuery(this).attr("maxhour")); 
  823. if (jQuery(this).attr("minhour")) hMin = parseInt(jQuery(this).attr("minhour")); 
  824. jQuery(this).prop("readonly", "readonly"); 
  825. jQuery(this).timepicker({ 
  826. hourText: "' . __( 'Hour', WCPGSK_DOMAIN ) . '",  
  827. minuteText: "' . __( 'Minute', WCPGSK_DOMAIN ) . '",  
  828. hours: { starts: hMin, ends: hMax },  
  829. minutes: { interval: parseInt(jQuery(this).attr("minutesteps")) },  
  830. rows: ( parseInt(jQuery(this).attr("minutesteps")) < 5 ? 6 : ( parseInt(jQuery(this).attr("minutesteps")) < 10 ? 4 : 3 ) ),  
  831. showPeriodLabels: false,  
  832. closeButtonText: "' . __( 'Close', WCPGSK_DOMAIN ) . '",  
  833. showCloseButton: true,  
  834.  
  835. });; 
  836. });'; 
  837.  
  838. else : 
  839.  
  840. echo ' jQuery("input[display=\'time\']").each(function() { 
  841. var hMax = 23; 
  842. var hMin = 0; 
  843. if (jQuery(this).attr("maxhour")) hMax = parseInt(jQuery(this).attr("maxhour")); 
  844. if (jQuery(this).attr("minhour")) hMin = parseInt(jQuery(this).attr("minhour")); 
  845.  
  846. jQuery(this).prop("readonly", "readonly"); 
  847.  
  848. jQuery(this).timepicker({ 
  849. timeFormat: "HH:mm",  
  850. hourMax: hMax,  
  851. hourMin: hMin,  
  852. stepHour: parseInt(jQuery(this).attr("hoursteps")),  
  853. stepMinute: parseInt(jQuery(this).attr("minutesteps")),  
  854. addSliderAccess: true,  
  855. sliderAccessArgs: { touchonly: false },  
  856. timeText: "' . __('Time', WCPGSK_DOMAIN) . '",  
  857. hourText: "' . __('Hour', WCPGSK_DOMAIN) . '",  
  858. minuteText: "' . __('Minute', WCPGSK_DOMAIN) . '",  
  859. currentText: cTT,  
  860. closeText: cT,  
  861. timeOnlyTitle: "' . __('Choose Time', WCPGSK_DOMAIN) . '" 
  862. });  
  863. });'; 
  864. endif; 
  865.  
  866. echo 'jQuery("input[display=\'number\']").each(function() { 
  867. var $this = this; 
  868. jQuery(this).after("<div id=\'slider_" + jQuery(this).attr("id") + "\'></div>"); 
  869. if ( jQuery($this).attr("minvalue") ) { 
  870. jQuery($this).attr("min", jQuery($this).attr("minvalue") ); 
  871. if ( jQuery($this).attr("rangemax") ) { 
  872. jQuery($this).attr("max", jQuery($this).attr("rangemax") ); 
  873. if ( jQuery($this).attr("maxvalue") ) { 
  874. jQuery($this).attr("max", jQuery($this).attr("maxvalue") ); 
  875. if ( jQuery(this).attr("numstep") ) { 
  876. jQuery($this).attr("step", jQuery($this).attr("numstep") ); 
  877. }  
  878.  
  879. if (jQuery($this).attr("numpres") == "true") { 
  880. jQuery("#slider_" + jQuery($this).attr("id")).slider({ 
  881. range: true,  
  882. min: parseInt(jQuery($this).attr("minvalue")),  
  883. max: parseInt(jQuery($this).attr("maxvalue")),  
  884. step: parseInt(jQuery($this).attr("numstep")),  
  885. values: [ parseInt(jQuery($this).val()), parseInt(jQuery($this).attr("rangemax")) ],  
  886. slide: function( event, ui ) { 
  887. jQuery( $this ).val( ui.values[0] + " - " + ui.values[1]); 
  888. }  
  889. }); 
  890. else { 
  891. jQuery($this).attr("type", "number"); 
  892.  
  893. jQuery("#slider_" + jQuery($this).attr("id")).slider({ 
  894. range: jQuery($this).attr("numpres"),  
  895. min: parseInt(jQuery($this).attr("minvalue")),  
  896. max: parseInt(jQuery($this).attr("maxvalue")),  
  897. step: parseInt(jQuery($this).attr("numstep")),  
  898. value: parseInt(jQuery($this).val()),  
  899. slide: function( event, ui ) { 
  900. jQuery( $this ).val( ui.value ); 
  901. }  
  902. }).sliderAccess({ touchonly : true }); 
  903. }); 
  904.  
  905. jQuery("select[presentation=\'radio\']").each(function(i, select) { 
  906. var $select = jQuery(select); 
  907. $select.find("option").each(function(j, option) { 
  908. var $option = jQuery(option); 
  909. // Create a radio: 
  910. if ($option.val() != null && $option.val() != "") { 
  911. var $radio = jQuery("<input type=\'radio\' />"); 
  912. // Set name and value: 
  913. $radio.attr("name", $select.attr("name")).attr("value", $option.val()).attr("class", "radio").attr("style", "width:10%"); 
  914. // Set checked if the option was selected 
  915. if ($option.attr("selected") != null && $option.attr("selected") == "selected" && $select.attr("hasselected") != null && $select.attr("hasselected") == "true" ) $radio.attr("checked", "checked"); 
  916. //$radio.text($option.text()); 
  917. // Insert radio before select box: 
  918. $select.before($radio); 
  919. // Insert a label: 
  920. $select.before( 
  921. jQuery("<span />").attr("for", $select.attr("name")).text($option.text()) 
  922. ); 
  923. // Insert a <br />: 
  924. $select.before("<br/>"); 
  925. }); 
  926. $select.remove(); 
  927. }); 
  928.  
  929. jQuery("select[presentation=\'checkbox\']").each(function(i, select) { 
  930. var $select = jQuery(select); 
  931. $select.find("option").each(function(j, option) { 
  932. var $option = jQuery(option); 
  933. // Create a radio: 
  934. if ($option.val() != null && $option.val() != "") { 
  935. var $radio = jQuery("<input type=\'checkbox\' />"); 
  936. // Set name and value: 
  937. $radio.attr("name", $select.attr("name") + "[" + j + "]").attr("value", $option.val()).attr("class", "checkbox").attr("style", "width:10%"); 
  938. // Set checked if the option was selected 
  939. if ($option.attr("selected") != null && $option.attr("selected") == "selected" && $select.attr("hasselected") != null && $select.attr("hasselected") == "true" ) $radio.attr("checked", "checked"); 
  940. //$radio.text($option.text()); 
  941. // Insert radio before select box: 
  942. $select.before($radio); 
  943. // Insert a label: 
  944. $select.before( 
  945. jQuery("<span />").attr("for", $select.attr("name")).text($option.text()) 
  946. ); 
  947. $select.before("<br/>"); 
  948. }); 
  949. $select.remove(); 
  950. }); 
  951. jQuery("select[multiple=\'multiple\']").each(function(i, select) { 
  952. var $select = jQuery(select); 
  953. $select.attr("name", $select.attr("name") + "[]"); 
  954. }); 
  955.  
  956. }); 
  957. </script><!--unit test after checkout end-->'; 
  958. //load our user scripts from db... 
  959. $wcpgsk_checkoutjs = get_option('wcpgsk_checkoutjs'); 
  960. if ( !empty($wcpgsk_checkoutjs) ) : 
  961. echo '<script language="javascript">'; 
  962. echo $wcpgsk_checkoutjs; 
  963. echo '</script>'; 
  964. endif; 
  965. endif; 
  966.  
  967.  
  968. /** 
  969. * Handle functions deprecated in WooCommerce since 2.1.0 for WooCommerce installations < 2.1 
  970. */ 
  971. function wcpgsk_add_error( $error ) { 
  972. if ( function_exists('WC') && function_exists('wc_add_notice') ) : 
  973. wc_add_notice( $error, 'error'); 
  974. else : 
  975. global $woocommerce; 
  976. $woocommerce->add_error( $error ); 
  977. endif; 
  978.  
  979. function wcpgsk_add_message( $message ) { 
  980. if ( function_exists('WC') && function_exists('wc_add_notice') ) : 
  981. wc_add_notice( $message ); 
  982. else : 
  983. global $woocommerce; 
  984. $woocommerce->add_message( $message ); 
  985. endif; 
  986.  
  987. function wcpgsk_clear_messages() { 
  988. if ( function_exists('WC') && function_exists('wc_clear_notices') ) : 
  989. wc_clear_notices(); 
  990. else : 
  991. global $woocommerce; 
  992. $woocommerce->clear_messages(); 
  993. endif; 
  994.  
  995. function wcpgsk_show_messages() { 
  996. if ( function_exists('WC') && function_exists('wc_print_notices') ) : 
  997. wc_print_notices(); 
  998. else : 
  999. global $woocommerce; 
  1000. $woocommerce->show_messages(); 
  1001. endif; 
  1002.  
  1003. function wcpgsk_set_messages() { 
  1004. if ( !function_exists('WC') ) : 
  1005. global $woocommerce; 
  1006. $woocommerce->set_messages(); 
  1007. endif; 
.