catchaddtocart

GQ class.

Defined (2)

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

/includes/class-catch-add-to-cart.php  
  1. class catchaddtocart{ 
  2. /** 
  3. * Plugin version, used for cache-busting of style and script file references. 
  4. * @since 1.0.0 
  5. * @var string 
  6. */ 
  7. protected $version = "1.0.0"; 
  8.  
  9. /** 
  10. * Unique identifier for your plugin. 
  11. * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should 
  12. * match the Text Domain file header in the main plugin file. 
  13. * @since 1.0.0 
  14. * @var string 
  15. */ 
  16. protected $plugin_slug = "gq"; 
  17.  
  18. /** 
  19. * Instance of this class. 
  20. * @since 1.0.0 
  21. * @var object 
  22. */ 
  23. protected static $instance = null; 
  24.  
  25. /** 
  26. * Slug of the plugin screen. 
  27. * @since 1.0.0 
  28. * @var string 
  29. */ 
  30. protected $plugin_screen_hook_suffix = null; 
  31.  
  32. /** 
  33. * Initialize the plugin by setting localization, filters, and administration functions. 
  34. * @since 1.0.0 
  35. */ 
  36. private function __construct() { 
  37.  
  38. //add_filter( 'woocommerce_available_variation', array($this, 'jk_woocommerce_available_variation') ); 
  39. add_filter( 'woocommerce_add_to_cart_validation', array($this, 'filter_woocommerce_add_to_cart_validation'), 10, 10 ); 
  40. /** 
  41. * Return an instance of this class. 
  42. * @since 1.0.0 
  43. * @return object A single instance of this class. 
  44. */ 
  45. public static function get_instance() { 
  46.  
  47. // If the single instance hasn"t been set, set it now. 
  48. if (null == self::$instance) { 
  49. self::$instance = new self; 
  50.  
  51. return self::$instance; 
  52. /** 
  53. */ 
  54. public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '' ) { 
  55. global $woocommerce; 
  56.  
  57. $product = wc_get_product( $product_id ); 
  58. if($product->product_type === "variable") { 
  59. $deductornot = get_post_meta( $variation_id, '_deductornot', true ); 
  60. $deductamount = get_post_meta( $variation_id, '_deductamount', true ); 
  61. $getvarclass = new WC_Product_Variation($variation_id); 
  62. //reset($array); 
  63. $aatrs = $getvarclass->get_variation_attributes(); 
  64. foreach($aatrs as $key => $value) { 
  65. $slug = $value; 
  66. $cat = str_replace('attribute_', '', $key); 
  67. $titlevaria = get_term_by('slug', $slug, $cat ); 
  68.  
  69. $backorder = get_post_meta( $product->post->ID, '_backorders', true ); 
  70.  
  71. $string = WC_Cart::get_item_data( $cart_item, $flat ); 
  72.  
  73. //var_dump($string); 
  74. if($backorder == 'no') { 
  75. if($deductornot == "yes") { 
  76. $currentstock = $product->get_stock_quantity(); 
  77.  
  78. $reduceamount = intval($quantity) * intval($deductamount); 
  79. $currentavail = intval($currentstock / $deductamount); 
  80.  
  81.  
  82. if($reduceamount > $currentstock) { 
  83. $valid = false; 
  84. wc_add_notice( ''.__( 'You that goes over our availble stock amount.' , 'woocommerce' ) . __( 'We have: ' , 'woocommerce' ) . $currentavail .' '. $product->post->post_title .' ' .$titlevaria->name.'\'s '.__( ' available.' , 'woocommerce' ) , 'error' ); 
  85. return $valid; 
  86. }else{ 
  87. $valid = true; 
  88. return $valid; 
  89.  
  90. }else{ 
  91. return true; 
  92. return true; 
  93.  
  94. /** 
  95. *@TODO implement max min quanties on picker 
  96. */ 
  97. public function jk_woocommerce_available_variation( $args ) { 
  98.  
  99. global $product; 
  100. //defaults 
  101. $variation_ids = array(); 
  102. $i = 0; 
  103.  
  104. foreach($product->children as $key => $value) { 
  105.  
  106. $variation_ids[$i] = $value; 
  107.  
  108. $i++; 
  109.  
  110. foreach($variation_ids as $key => $value) { 
  111.  
  112. $deductornot = get_post_meta( $value, '_deductornot', true );; 
  113. $deductamount = get_post_meta( $value, '_deductamount', true );; 
  114.  
  115. $args['max_qty'] = 80; // Maximum value (variations) 
  116. $args['min_qty'] = 2; // Minimum value (variations) 
  117. return $args; 
  118.  
  119.  
/trunk/includes/class-catch-add-to-cart.php  
  1. class catchaddtocart{ 
  2. /** 
  3. * Plugin version, used for cache-busting of style and script file references. 
  4. * @since 1.0.0 
  5. * @var string 
  6. */ 
  7. protected $version = "1.0.0"; 
  8.  
  9. /** 
  10. * Unique identifier for your plugin. 
  11. * Use this value (not the variable name) as the text domain when internationalizing strings of text. It should 
  12. * match the Text Domain file header in the main plugin file. 
  13. * @since 1.0.0 
  14. * @var string 
  15. */ 
  16. protected $plugin_slug = "gq"; 
  17.  
  18. /** 
  19. * Instance of this class. 
  20. * @since 1.0.0 
  21. * @var object 
  22. */ 
  23. protected static $instance = null; 
  24.  
  25. /** 
  26. * Slug of the plugin screen. 
  27. * @since 1.0.0 
  28. * @var string 
  29. */ 
  30. protected $plugin_screen_hook_suffix = null; 
  31.  
  32. /** 
  33. * Initialize the plugin by setting localization, filters, and administration functions. 
  34. * @since 1.0.0 
  35. */ 
  36. private function __construct() { 
  37.  
  38. //add_filter( 'woocommerce_available_variation', array($this, 'jk_woocommerce_available_variation') ); 
  39. add_filter( 'woocommerce_add_to_cart_validation', array($this, 'filter_woocommerce_add_to_cart_validation'), 10, 10 ); 
  40. /** 
  41. * Return an instance of this class. 
  42. * @since 1.0.0 
  43. * @return object A single instance of this class. 
  44. */ 
  45. public static function get_instance() { 
  46.  
  47. // If the single instance hasn"t been set, set it now. 
  48. if (null == self::$instance) { 
  49. self::$instance = new self; 
  50.  
  51. return self::$instance; 
  52. /** 
  53. */ 
  54. public function filter_woocommerce_add_to_cart_validation($valid, $product_id, $quantity, $variation_id = '', $variations = '' ) { 
  55. global $woocommerce; 
  56.  
  57. $product = wc_get_product( $product_id ); 
  58. if($product->product_type === "variable") { 
  59. $deductornot = get_post_meta( $variation_id, '_deductornot', true ); 
  60. $deductamount = get_post_meta( $variation_id, '_deductamount', true ); 
  61. $getvarclass = new WC_Product_Variation($variation_id); 
  62. //reset($array); 
  63. $aatrs = $getvarclass->get_variation_attributes(); 
  64. foreach($aatrs as $key => $value) { 
  65. $slug = $value; 
  66. $cat = str_replace('attribute_', '', $key); 
  67. $titlevaria = get_term_by('slug', $slug, $cat ); 
  68.  
  69. $backorder = get_post_meta( $product->post->ID, '_backorders', true ); 
  70.  
  71. $string = WC_Cart::get_item_data( $cart_item, $flat ); 
  72.  
  73. //var_dump($string); 
  74. if($backorder == 'no') { 
  75. if($deductornot == "yes") { 
  76. $currentstock = $product->get_stock_quantity(); 
  77.  
  78. $reduceamount = intval($quantity) * intval($deductamount); 
  79. $currentavail = intval($currentstock / $deductamount); 
  80.  
  81.  
  82. if($reduceamount > $currentstock) { 
  83. $valid = false; 
  84. wc_add_notice( ''.__( 'You that goes over our availble stock amount.' , 'woocommerce' ) . __( 'We have: ' , 'woocommerce' ) . $currentavail .' '. $product->post->post_title .' ' .$titlevaria->name.'\'s '.__( ' available.' , 'woocommerce' ) , 'error' ); 
  85. return $valid; 
  86. }else{ 
  87. $valid = true; 
  88. return $valid; 
  89.  
  90. }else{ 
  91. return true; 
  92. return true; 
  93.  
  94. /** 
  95. *@TODO implement max min quanties on picker 
  96. */ 
  97. public function jk_woocommerce_available_variation( $args ) { 
  98.  
  99. global $product; 
  100. //defaults 
  101. $variation_ids = array(); 
  102. $i = 0; 
  103.  
  104. foreach($product->children as $key => $value) { 
  105.  
  106. $variation_ids[$i] = $value; 
  107.  
  108. $i++; 
  109.  
  110. foreach($variation_ids as $key => $value) { 
  111.  
  112. $deductornot = get_post_meta( $value, '_deductornot', true );; 
  113. $deductamount = get_post_meta( $value, '_deductamount', true );; 
  114.  
  115. $args['max_qty'] = 80; // Maximum value (variations) 
  116. $args['min_qty'] = 2; // Minimum value (variations) 
  117. return $args; 
  118.  
  119.