@@ -128,15 +128,18 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
128128 $ lock_default_location = isset ( $ this ->plugin_settings ['lock_default_location_in_frontend ' ] ) && $ this ->plugin_settings ['lock_default_location_in_frontend ' ] == 'on ' ? true : false ;
129129 $ stock_location_selected = ((isset ($ woocommerce ->session ) && $ woocommerce ->session ->has_session ())?$ woocommerce ->session ->get ('stock_location_selected ' ):0 );
130130
131+
131132 $ different_location_per_cart_item = (isset ($ this ->plugin_settings ['different_location_per_cart_item ' ])?$ this ->plugin_settings ['different_location_per_cart_item ' ]:'' );
132133 $ different_location_per_cart_item_no = (isset ($ this ->plugin_settings ['different_location_per_cart_item_no ' ])?$ this ->plugin_settings ['different_location_per_cart_item_no ' ]:'' );
133134
134135
135136
136137 if (array_key_exists ('stock_location ' , $ cart_item ) && !is_array ($ cart_item ['stock_location ' ]) && $ cart_item ['stock_location ' ]>0 ){
138+ $ stock_location_selected = ($ stock_location_selected ?$ stock_location_selected :$ cart_item ['stock_location ' ]);
137139 $ cart_item ['stock_location ' ] = (is_array ($ cart_item ['stock_location ' ])?$ cart_item ['stock_location ' ]:array ($ product_id =>$ cart_item ['stock_location ' ]));
138140 }
139-
141+
142+
140143 if ( !empty ($ stock_locations ) ) {
141144
142145 if ( isset ($ this ->plugin_settings ['show_in_cart ' ]) && $ this ->plugin_settings ['show_in_cart ' ] == 'yes ' ) {
@@ -146,7 +149,7 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
146149 $ stock_locations_arr [] = $ location ['term_id ' ];
147150 }
148151
149- if (!in_array ($ stock_location_selected , $ stock_locations_arr ) && $ different_location_per_cart_item =='no ' && $ different_location_per_cart_item_no == 'continue ' ){
152+ if ($ stock_location_selected && !in_array ($ stock_location_selected , $ stock_locations_arr ) && $ different_location_per_cart_item =='no ' && $ different_location_per_cart_item_no == 'continue ' ){
150153 $ product_name = ($ cart_item ['data ' ]->get_data ()['name ' ]);
151154
152155 $ slw_notice_msg = apply_filters ('slw_notice_msg ' , sprintf ( __ ('This product item is not available on the selected store location. %s ' , 'stock-locations-for-woocommerce ' ), '<a class="button alt slw-dismiss-notice"> ' .__ ('Dismiss ' , 'stock-locations-for-woocommerce ' ).'</a> ' ), $ product_id , $ product_name , $ stock_location_selected , $ stock_locations_arr );
@@ -156,27 +159,33 @@ public function add_cart_item_stock_locations( $cart_item, $cart_item_key )
156159 }
157160
158161 if (
159- isset ($ this ->plugin_settings ['different_location_per_cart_item ' ])
160- &&
161162 (
162- $ this ->plugin_settings ['different_location_per_cart_item ' ] == 'yes '
163-
164- ||
165-
166- (
167- $ this ->plugin_settings ['different_location_per_cart_item ' ] == 'no '
168- &&
169- (
170- in_array ($ stock_location_selected , $ stock_locations_arr )
171- //||
172- //$different_location_per_cart_item_no == 'continue'
173- )
174-
175- )
163+ isset ($ this ->plugin_settings ['different_location_per_cart_item ' ])
164+ &&
165+ (
166+ $ this ->plugin_settings ['different_location_per_cart_item ' ] == 'yes '
167+
168+ ||
169+
170+ (
171+ $ this ->plugin_settings ['different_location_per_cart_item ' ] == 'no '
172+ &&
173+ (
174+ in_array ($ stock_location_selected , $ stock_locations_arr )
175+ //||
176+ //$different_location_per_cart_item_no == 'continue'
177+ )
178+
179+ )
180+ )
176181 )
182+
183+ ||
184+
185+ !$ stock_location_selected
177186 ) {
178187
179- echo '<label class="slw_cart_item_stock_location_label"> ' .__ ('Nearest Location ' , 'stock-locations-for-woocommerce ' ).':</label> ' ;
188+ echo '<label class="slw_cart_item_stock_location_label"> ' .__ ('Location ' , 'stock-locations-for-woocommerce ' ).':</label> ' ;
180189
181190 // lock to default location if enabled
182191 if ( $ lock_default_location && $ default_location != 0 ) {
0 commit comments