1 <?php
2
3 4 5 6 7 8 9 10 11
12
13 namespace WC_POS;
14
15 class Products {
16
17 18 19
20 public function __construct() {
21 add_action( 'woocommerce_product_set_stock', array( $this, 'product_set_stock') );
22 add_action( 'woocommerce_variation_set_stock', array( $this, 'product_set_stock') );
23 $this->init();
24 }
25
26 27 28
29 private function init() {
30
31
32 if( wc_pos_get_option( 'general', 'pos_only_products' ) ) {
33 new Products\Visibility();
34 }
35
36
37 if( wc_pos_get_option( 'general', 'decimal_qty' ) ){
38 remove_filter('woocommerce_stock_amount', 'intval');
39 add_filter( 'woocommerce_stock_amount', 'floatval' );
40 }
41
42 }
43
44 45 46 47 48
49 public function product_set_stock( $product ){
50 $post_modified = current_time( 'mysql' );
51 $post_modified_gmt = current_time( 'mysql', 1 );
52 wp_update_post( array(
53 'ID' => $product->id,
54 'post_modified' => $post_modified,
55 'post_modified_gmt' => $post_modified_gmt
56 ));
57 }
58
59 }