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

Commit

Permalink
fixes #234
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Jon007 committed May 23, 2019
1 parent 7ef8ef6 commit 3bbc1bf
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Hyyan/WPI/Product/Product.php
Expand Up @@ -12,6 +12,7 @@

use Hyyan\WPI\Admin\Settings;
use Hyyan\WPI\Admin\Features;
use Hyyan\WPI\Utilities;

/**
* Product.
Expand Down Expand Up @@ -59,6 +60,9 @@ public function __construct()
add_filter('woocommerce_product_get_cross_sell_ids', array($this, 'getCrosssellsInLanguage'), 10, 2);
add_filter('woocommerce_product_get_children', array($this, 'getChildrenInLanguage'), 10, 2);

//for this ajax call our action has to come before the woocommerce action because the woocommerce action does a redirect
add_action( 'wp_ajax_woocommerce_feature_product', array( __CLASS__, 'sync_ajax_woocommerce_feature_product' ), 5 );

new Meta();
new Variable();
new Duplicator();
Expand All @@ -68,6 +72,35 @@ public function __construct()
}
}


/*
* #234 WooCommerce allows featured to be toggled in the products admin list
* by clicking on the star
*/
public static function sync_ajax_woocommerce_feature_product() {
$metas = Meta::getDisabledProductMetaToCopy();
if ( in_array( '_visibility', $metas ) ) {
return;
}

$product = wc_get_product( absint( $_GET[ 'product_id' ] ) );
if ( $product ) {
//woocommerce action runs last so we need to set translation feature to the opposite of current value
$targetValue = ! $product->get_featured();

$product_translations = Utilities::getProductTranslationsArrayByObject( $product );
foreach ( $product_translations as $product_translation ) {
if ( $product_translation != $product->get_id() ) {
$translation = wc_get_product( $product_translation );
if ( $translation ) {
$translation->set_featured( $targetValue );
$translation->save();
}
}
}
}
}


/**
* filter child ids of Grouped Product
Expand Down

0 comments on commit 3bbc1bf

Please sign in to comment.