WC_POS_Products

POS Product Class duck punches the WC REST API.

Defined (1)

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

/includes/class-wc-pos-products.php  
  1. class WC_POS_Products { 
  2.  
  3. /** 
  4. * Constructor 
  5. */ 
  6. public function __construct() { 
  7. $this->init(); 
  8.  
  9. add_action( 'woocommerce_product_set_stock', array( $this, 'product_set_stock') ); 
  10. add_action( 'woocommerce_variation_set_stock', array( $this, 'product_set_stock') ); 
  11.  
  12.  
  13. /** 
  14. * Load Product subclasses 
  15. */ 
  16. private function init() { 
  17.  
  18. // pos only products 
  19. if( wc_pos_get_option( 'general', 'pos_only_products' ) ) { 
  20. new WC_POS_Products_Visibility(); 
  21.  
  22. // decimal quantities 
  23. if( wc_pos_get_option( 'general', 'decimal_qty' ) ) { 
  24. remove_filter('woocommerce_stock_amount', 'intval'); 
  25. add_filter( 'woocommerce_stock_amount', 'floatval' ); 
  26.  
  27.  
  28. /** 
  29. * Bump modified date on stock change 
  30. * - variation->id = parent id 
  31. * @param $product 
  32. */ 
  33. public function product_set_stock( $product ) { 
  34. $post_modified = current_time( 'mysql' ); 
  35. $post_modified_gmt = current_time( 'mysql', 1 ); 
  36.  
  37. if( version_compare( WC()->version, '3', '<' ) ) { 
  38. $id = $product->id; 
  39. } else { 
  40. $id = $product->get_id(); 
  41.  
  42. wp_update_post( array( 
  43. 'ID' => $id,  
  44. 'post_modified' => $post_modified,  
  45. 'post_modified_gmt' => $post_modified_gmt 
  46. )); 
  47.