Skip to content

Commit 0b1f9ee

Browse files
committed
3.0.1
1 parent c57573e commit 0b1f9ee

File tree

2 files changed

+84
-82
lines changed

2 files changed

+84
-82
lines changed

src/src/helpers/helper-slw-product.php

Lines changed: 82 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,87 @@
1111

1212
if ( ! defined( 'WPINC' ) ) die;
1313

14+
15+
16+
if ( ! function_exists( __NAMESPACE__ . '\slw_product_wc_stock_status_callback' ) ) {
17+
function slw_product_wc_stock_status_callback( $locations_stock, $id, $force_main_product_stock_status_to_instock = false ) {
18+
19+
static $processing = [];
20+
21+
if ( isset($processing[$id]) && $processing[$id] ) {
22+
return;
23+
}
24+
25+
$processing[$id] = true;
26+
27+
global $slw_plugin_settings;
28+
if ( ! is_array( $slw_plugin_settings ) ) {
29+
$slw_plugin_settings = [];
30+
}
31+
32+
$force_main_product_stock_status_to_instock = (!$force_main_product_stock_status_to_instock?array_key_exists('force_main_product_stock_status_to_instock', $slw_plugin_settings):$force_main_product_stock_status_to_instock);
33+
34+
if(is_numeric($id)){
35+
//pree($id);
36+
$product = wc_get_product( $id );
37+
}
38+
39+
if(is_object($id)){
40+
$product = $id;
41+
$id = $product->get_id();
42+
}
43+
44+
if( ! empty( $id ) && $force_main_product_stock_status_to_instock) {
45+
46+
if( empty( $product ) ) return;
47+
48+
$parent_id = $product->get_parent_id();
49+
50+
51+
if( $parent_id == 0 ) {
52+
53+
54+
55+
if(!$locations_stock){
56+
$locations_stock = \SLW\SRC\Helpers\SlwProductHelper::get_product_locations_stock_total( $id );
57+
}
58+
59+
$_backorders = get_post_meta($id, '_backorders', true);
60+
$_backorder_status = ($_backorders!='no');
61+
62+
if($_backorder_status){
63+
update_post_meta( $id, '_stock_status', 'onbackorder' );
64+
}else{
65+
if( $locations_stock > 0 ) {
66+
update_post_meta( $id, '_stock_status', 'instock' );
67+
}elseif( $locations_stock <= 0 ) {
68+
69+
update_post_meta( $id, '_stock_status', 'outofstock' );
70+
71+
}
72+
}
73+
74+
// Temporarily remove this callback while we call the updater to avoid recursion
75+
remove_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10 );
76+
77+
// call the function that actually updates the main product stock status
78+
\slw_update_product_stock_status( $id, $locations_stock );
79+
80+
// re-add the callback
81+
add_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10, 3 );
82+
83+
84+
85+
}
86+
}
87+
88+
unset( $processing[$id] );
89+
90+
}
91+
}
92+
add_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10, 3 );
93+
94+
1495
if ( ! class_exists( 'SlwProductHelper' ) ) {
1596

1697
class SlwProductHelper
@@ -104,7 +185,7 @@ public static function call_wc_product_stock_status_action( $product_id, $status
104185
$approved_status_string = array('instock', 'outofstock', 'onbackorder');
105186
if ( ! in_array( $status, $approved_status_string ) ) return;
106187
$product_id = (int) $product_id;
107-
pree($product_id);
188+
//pree($product_id);
108189
$product = wc_get_product( $product_id );
109190
if ( $product->is_type( 'variation' ) ) {
110191
do_action( 'woocommerce_variation_set_stock_status', $product_id, $status, $product );
@@ -137,82 +218,3 @@ public static function get_product_locations_stock_total( $product, $stock_locat
137218
}
138219

139220
}
140-
141-
142-
if ( ! function_exists( __NAMESPACE__ . '\slw_product_wc_stock_status_callback' ) ) {
143-
function slw_product_wc_stock_status_callback( $locations_stock, $id, $force_main_product_stock_status_to_instock = false ) {
144-
145-
static $processing = [];
146-
147-
if ( isset($processing[$id]) && $processing[$id] ) {
148-
return;
149-
}
150-
151-
$processing[$id] = true;
152-
153-
global $slw_plugin_settings;
154-
if ( ! is_array( $slw_plugin_settings ) ) {
155-
$slw_plugin_settings = [];
156-
}
157-
158-
$force_main_product_stock_status_to_instock = (!$force_main_product_stock_status_to_instock?array_key_exists('force_main_product_stock_status_to_instock', $slw_plugin_settings):$force_main_product_stock_status_to_instock);
159-
160-
if(is_numeric($id)){
161-
//pree($id);
162-
$product = wc_get_product( $id );
163-
}
164-
165-
if(is_object($id)){
166-
$product = $id;
167-
$id = $product->get_id();
168-
}
169-
170-
if( ! empty( $id ) && $force_main_product_stock_status_to_instock) {
171-
172-
if( empty( $product ) ) return;
173-
174-
$parent_id = $product->get_parent_id();
175-
176-
177-
if( $parent_id == 0 ) {
178-
179-
180-
181-
if(!$locations_stock){
182-
$locations_stock = \SLW\SRC\Helpers\SlwProductHelper::get_product_locations_stock_total( $id );
183-
}
184-
185-
$_backorders = get_post_meta($id, '_backorders', true);
186-
$_backorder_status = ($_backorders!='no');
187-
188-
if($_backorder_status){
189-
update_post_meta( $id, '_stock_status', 'onbackorder' );
190-
}else{
191-
if( $locations_stock > 0 ) {
192-
update_post_meta( $id, '_stock_status', 'instock' );
193-
}elseif( $locations_stock <= 0 ) {
194-
195-
update_post_meta( $id, '_stock_status', 'outofstock' );
196-
197-
}
198-
}
199-
200-
// Temporarily remove this callback while we call the updater to avoid recursion
201-
remove_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10 );
202-
203-
// call the function that actually updates the main product stock status
204-
\slw_update_product_stock_status( $id, $locations_stock );
205-
206-
// re-add the callback
207-
add_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10, 3 );
208-
209-
210-
211-
}
212-
}
213-
214-
unset( $processing[$id] );
215-
216-
}
217-
}
218-
add_action( 'slw_product_wc_stock_status', __NAMESPACE__ . '\slw_product_wc_stock_status_callback', 10, 3 );

src/stock-locations-for-woocommerce.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
class SlwMain{
8181
// versions
82-
public $version = '3.0.0';
82+
public $version = '3.0.1';
8383
public $import_export_addon_version = '1.1.1';
8484

8585
// others
@@ -335,7 +335,7 @@ public function enqueue_frontend()
335335
$data = (is_array($this->plugin_settings)?$this->plugin_settings:array());
336336
$data['slw_wc_hide_out_of_stock'] = $slw_wc_hide_out_of_stock;
337337
$data['slw_location_selection'] = get_option('slw-location-selection', 'no');
338-
$data['slw_location_selection_popup'] = (apply_filters('slw_location_selection_popup_display', is_front_page(), is_shop()) && function_exists('slw_location_selection_popup') && (get_option('slw-location-selection', 'no')=='yes')?slw_location_selection_popup():'');
338+
$data['slw_location_selection_popup'] = (apply_filters('slw_location_selection_popup_display', is_front_page(), is_shop()) && function_exists('slw_location_selection_popup') && (get_option('slw-location-selection', 'no')=='yes')?slw_location_selection_popup($product_id):'');
339339
$data['is_home_page'] = (is_home()?'yes':'no');
340340
$data['is_front_page'] = (is_front_page()?'yes':'no');
341341
$data['ajaxurl'] = admin_url( 'admin-ajax.php' );

0 commit comments

Comments
 (0)