Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit 08c9913

Browse files
committed
stock enhancements - ignore missing translations
avoid errors logged when product is not translated
1 parent 77c9599 commit 08c9913

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Hyyan/WPI/Product/Stock.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public static function SyncStock( \WC_Product $product ) {
7878
Variation::getRelatedVariation( get_post_meta( $product_with_stock->get_id(), Variation::DUPLICATE_KEY, true ), true ) :
7979
Utilities::getProductTranslationsArrayByObject( $product_with_stock );
8080

81-
foreach ( $product_translations as $product_translation ) {
82-
if ( $product_translation != $product_with_stock->get_id() ) {
83-
$translation = wc_get_product( $product_translation );
84-
if ( $translation ) {
85-
wc_update_product_stock( $translation, $targetValue );
81+
if ( $product_translations ) {
82+
foreach ( $product_translations as $product_translation ) {
83+
if ( $product_translation != $product_with_stock->get_id() ) {
84+
$translation = wc_get_product( $product_translation );
85+
if ( $translation ) {
86+
wc_update_product_stock( $translation, $targetValue );
87+
}
8688
}
8789
}
8890
}

src/Hyyan/WPI/Product/Variation.php

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public function duplicate()
109109
public static function getRelatedVariation($variatonID, $returnIDS = false)
110110
{
111111
$result = array();
112+
if ( ! $variatonID ) {
113+
return false;
114+
}
112115

113116
//previous version of code using get_post_meta() was filtered at runtime by Polylang
114117
//even when adding 'suppress_filters' => true, so there was no way to adjust stock

0 commit comments

Comments
 (0)