diff --git a/src/compatibility/index.php b/src/compatibility/index.php index 0421aef29..f6afca5fe 100644 --- a/src/compatibility/index.php +++ b/src/compatibility/index.php @@ -6,3 +6,4 @@ } require_once( plugin_dir_path( __FILE__ ) . './neve/index.php' ); +require_once( plugin_dir_path( __FILE__ ) . './woocommerce.php' ); diff --git a/src/compatibility/woocommerce.php b/src/compatibility/woocommerce.php new file mode 100644 index 000000000..47dfe27f0 --- /dev/null +++ b/src/compatibility/woocommerce.php @@ -0,0 +1,60 @@ + tags are stripped out and the CSS styles are displayed in the frontend. + * This function removes the ', '', $content ); + } + + return $content; + } + + function is_woocommerce_shop_page() { + // only add filter when on the WooCommerce Shop page + if ( function_exists('is_shop' ) && is_shop() ) { + add_filter('pre_kses', 'stackable_pre_kses_woocomerce_shop', 10, 3); + } + + } + + add_action( 'woocommerce_before_main_content', 'is_woocommerce_shop_page' ); +} + +if ( ! function_exists( 'stackable_check_if_woocommerce_shop' ) ) { + + function stackable_check_if_woocommerce_shop( $optimize_css ) { + // Load cached CSS for the WooCommerce Shop page + // is_singular() returns false when on the Shop page so we need to use is_shop() + return $optimize_css || ( function_exists('is_shop' ) && is_shop() ); + } + + add_filter( 'stackable/load_cached_css_for_post', 'stackable_check_if_woocommerce_shop' ); +} + +if ( ! function_exists( 'stackable_get_woocommerce_shop_page_id' ) ) { + + function stackable_get_woocommerce_shop_page_id( $post_id ) { + // use wc_get_page_id() to retrieve the page ID of the Shop page + // do this because get_the_ID() returns the product page ID when on the Shop page + if ( function_exists('is_shop' ) && is_shop() ) { + return wc_get_page_id( 'shop' ); + } + return $post_id; + } + + add_filter( 'stackable/get_post_id_for_cached_css', 'stackable_get_woocommerce_shop_page_id' ); + +} diff --git a/src/css-optimize.php b/src/css-optimize.php index 82e1620e7..c4ff1b3b7 100644 --- a/src/css-optimize.php +++ b/src/css-optimize.php @@ -213,8 +213,10 @@ public function load_cached_css_for_post() { // wp_template_part then we might need to use the actions: // render_block_core_template_part_post and // render_block_core_template_part_file - if ( is_singular() && ! is_preview() && ! is_attachment() ) { - $post_id = get_the_ID(); + $optimize_css = is_singular() && ! is_preview() && ! is_attachment(); + $optimize_css = apply_filters( 'stackable/load_cached_css_for_post', $optimize_css ); + if ( $optimize_css ) { + $post_id = apply_filters( 'stackable/get_post_id_for_cached_css', get_the_ID() ); $this->optimized_css = get_post_meta( $post_id, 'stackable_optimized_css', true ); if ( ! empty( $this->optimized_css ) ) {