Skip to content

Commit

Permalink
Enhancement/5984 woocommerce product sorting not woring with wpr (#5993)
Browse files Browse the repository at this point in the history
Co-authored-by: Vasilis Manthos <vmanthos@gmail.com>
  • Loading branch information
jeawhanlee and vmanthos committed Jul 6, 2023
1 parent b6914e2 commit b11a9ef
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions inc/ThirdParty/Plugins/Ecommerce/WooCommerceSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public static function get_subscribed_events() {

$events['wp_head'] = 'show_empty_product_gallery_with_delayJS';
$events['rocket_delay_js_exclusions'] = 'show_notempty_product_gallery_with_delayJS';

$events['wp_ajax_woocommerce_product_ordering'] = [ 'disallow_rocket_clean_post', 9 ];
$events['woocommerce_after_product_ordering'] = [ 'allow_rocket_clean_post' ];
}

if ( class_exists( 'WC_API' ) ) {
Expand Down Expand Up @@ -592,4 +595,39 @@ public function show_notempty_product_gallery_with_delayJS( $exclusions = [] ):

return array_merge( $exclusions, $exclusions_gallery );
}

/**
* Disable post cache clearing during product sorting.
*
* @return void
*/
public function disallow_rocket_clean_post() : void {
$this->event_manager->remove_callback( 'clean_post_cache', 'rocket_clean_post' );
}

/**
* Re-enable post cache clearing after product sorting.
*
* @param integer $product_id ID of sorted product.
* @return void
*/
public function allow_rocket_clean_post( int $product_id ) : void {
$urls = [];
$category_list = wc_get_product_category_list( $product_id );

if ( preg_match_all( '/<a\s+(?:[^>]*?\s+)?href=(["\'])(?<urls>.*?)\1/i', $category_list, $matches ) ) {
$urls = $matches['urls'];
}

$shop_page = get_permalink( wc_get_page_id( 'shop' ) );

if ( empty( $shop_page ) ) {
$shop_page = home_url( 'shop' );
}

$urls[] = $shop_page;

rocket_clean_files( $urls );
$this->event_manager->add_callback( 'clean_post_cache', 'rocket_clean_post' );
}
}

0 comments on commit b11a9ef

Please sign in to comment.