Skip to content

Commit

Permalink
Merge pull request #577 from qtwrk/dev
Browse files Browse the repository at this point in the history
WPML product category purge
  • Loading branch information
hi-hai committed Oct 11, 2023
2 parents 89864ea + f76851a commit 66e6b1a
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions thirdparty/woocommerce.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,20 +578,33 @@ public function set_control($esi_id)
*/
public function purge_product($product)
{
do_action('litespeed_debug', '[3rd] Woo Purge [pid]' . $product->get_id());
do_action('litespeed_debug', '[3rd] Woo Purge [pid] ' . $product->get_id());

$config = apply_filters('litespeed_conf', self::O_UPDATE_INTERVAL);
if (is_null($config)) {
$config = self::O_PQS_CS;
}
$do_purge = function ($action, $debug = '') use ($product) {
$config = apply_filters('litespeed_conf', self::O_UPDATE_INTERVAL);
if (is_null($config)) {
$config = self::O_PQS_CS;
}

if ($config === self::O_PQS_CQS) {
$this->backend_purge($product->get_id());
} elseif ($config !== self::O_PQS_CS && $product->is_in_stock()) {
do_action('litespeed_debug', '[3rd] Woo No purge needed [option] ' . $config);
if ($config === self::O_PQS_CQS) {
$action();
if ($debug) {
do_action('litespeed_debug', $debug);
}
} elseif ($config !== self::O_PQS_CS && $product->is_in_stock()) {
do_action('litespeed_debug', '[3rd] Woo No purge needed [option] ' . $config);
return false;
} elseif ($config !== self::O_PS_CN && !$product->is_in_stock()) {
$action();
if ($debug) {
do_action('litespeed_debug', $debug);
}
}
return true;
};

if (!$do_purge(function () use ($product) { $this->backend_purge($product->get_id()); })) {
return;
} elseif ($config !== self::O_PS_CN && !$product->is_in_stock()) {
$this->backend_purge($product->get_id());
}

do_action('litespeed_purge_post', $product->get_id());
Expand All @@ -613,6 +626,23 @@ public function purge_product($product)
do_action( 'litespeed_purge_post', $translation->element_id );
// use the $translation->element_id as it is post ID of other languages
}

// Check other languages category and purge if configured.
// wp_get_post_terms() only returns default language category ID
$default_cats = wp_get_post_terms($wpml_purge_id, 'product_cat');
$languages = apply_filters('wpml_active_languages', NULL);

foreach ($default_cats as $default_cat) {
foreach ($languages as $language) {
$tr_cat_id = icl_object_id($default_cat->term_id, 'product_cat', false, $language['code']);
$do_purge(
function () use ($tr_cat_id) {
do_action('litespeed_purge', self::CACHETAG_TERM . $tr_cat_id);
},
'[3rd] Woo Purge WPML category [language] ' . $language['code'] . ' [cat] ' . $tr_cat_id
);
}
}
}
}

Expand Down

0 comments on commit 66e6b1a

Please sign in to comment.