php - WooCommerce custom stock status -
i trying overwrite woocommerce_product_is_in_stock filter/hook, have found answer: additional stock options in woocommerce
add_filter('woocommerce_product_is_in_stock', 'woocommerce_product_is_in_stock' ); function woocommerce_product_is_in_stock( $is_in_stock ) { global $product; // array of custom stock statuses have add cart button $stock_statuses = array('onrequest','preorder'); if (!$is_in_stock && in_array($product->stock_status, $stock_statuses )) { $is_in_stock = true; } return $is_in_stock; }
but helps me partway, return product in stock instances whenever try view cart product cannot found. global $product seems "null" whenever var_dump it.
how can change code cart allow me order product own custom stock status?
thanks in advance!
i did updating woocommerce is_in_stock() function in woocommerce -> includes -> abstracts -> abstract-wc-product.php
public function is_in_stock() { if ( $this->managing_stock() && $this->backorders_allowed() ) { return true; } elseif ( $this->managing_stock() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) { return false; } else { return $this->stock_status === 'instock'; }
to
public function is_in_stock() { $stock_statuses = array('onrequest','preorder'); if ($this->get_total_stock() > get_option( 'woocommerce_notify_no_stock_amount' ) && in_array($this->stock_status, $stock_statuses )) { return true; } if ( $this->managing_stock() && $this->backorders_allowed() ) { return true; } elseif ( $this->managing_stock() && $this->get_total_stock() <= get_option( 'woocommerce_notify_no_stock_amount' ) ) { return false; } else { return $this->stock_status === 'instock'; } }
Comments
Post a Comment