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

Commit 3bbc1bf

Browse files
committed
fixes #234
fixes #234 by allowing the click on featured product from the products listing screen to cascade to translations, if the Hyyan Metas List, Visibility option is set (in WooCommerce 3+ Featured is now port of the visibility taxonomy)
1 parent 7ef8ef6 commit 3bbc1bf

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Hyyan/WPI/Product/Product.php

+33
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Hyyan\WPI\Admin\Settings;
1414
use Hyyan\WPI\Admin\Features;
15+
use Hyyan\WPI\Utilities;
1516

1617
/**
1718
* Product.
@@ -59,6 +60,9 @@ public function __construct()
5960
add_filter('woocommerce_product_get_cross_sell_ids', array($this, 'getCrosssellsInLanguage'), 10, 2);
6061
add_filter('woocommerce_product_get_children', array($this, 'getChildrenInLanguage'), 10, 2);
6162

63+
//for this ajax call our action has to come before the woocommerce action because the woocommerce action does a redirect
64+
add_action( 'wp_ajax_woocommerce_feature_product', array( __CLASS__, 'sync_ajax_woocommerce_feature_product' ), 5 );
65+
6266
new Meta();
6367
new Variable();
6468
new Duplicator();
@@ -68,6 +72,35 @@ public function __construct()
6872
}
6973
}
7074

75+
76+
/*
77+
* #234 WooCommerce allows featured to be toggled in the products admin list
78+
* by clicking on the star
79+
*/
80+
public static function sync_ajax_woocommerce_feature_product() {
81+
$metas = Meta::getDisabledProductMetaToCopy();
82+
if ( in_array( '_visibility', $metas ) ) {
83+
return;
84+
}
85+
86+
$product = wc_get_product( absint( $_GET[ 'product_id' ] ) );
87+
if ( $product ) {
88+
//woocommerce action runs last so we need to set translation feature to the opposite of current value
89+
$targetValue = ! $product->get_featured();
90+
91+
$product_translations = Utilities::getProductTranslationsArrayByObject( $product );
92+
foreach ( $product_translations as $product_translation ) {
93+
if ( $product_translation != $product->get_id() ) {
94+
$translation = wc_get_product( $product_translation );
95+
if ( $translation ) {
96+
$translation->set_featured( $targetValue );
97+
$translation->save();
98+
}
99+
}
100+
}
101+
}
102+
}
103+
71104

72105
/**
73106
* filter child ids of Grouped Product

0 commit comments

Comments
 (0)