From da06b597da311a78b2fe3183595b0496ee69e38e Mon Sep 17 00:00:00 2001 From: nikitasinelnikov Date: Thu, 21 Mar 2019 19:01:17 +0200 Subject: [PATCH] - fixed issue with restricted Woocommerce products --- includes/core/class-access.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index d1766151..4ca2e3e8 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -711,6 +711,8 @@ if ( ! class_exists( 'um\core\Access' ) ) { */ do_action( 'um_access_fix_external_post_content' ); + add_filter( 'single_template', array( &$this, 'woocommerce_template' ), 9999999, 1 ); + $filtered_posts[] = $post; continue; } elseif ( '1' == $restriction['_um_noaccess_action'] ) { @@ -825,6 +827,8 @@ if ( ! class_exists( 'um\core\Access' ) ) { */ do_action( 'um_access_fix_external_post_content' ); + add_filter( 'single_template', array( &$this, 'woocommerce_template' ), 9999999, 1 ); + $filtered_posts[] = $post; continue; } elseif ( '1' == $restriction['_um_noaccess_action'] ) { @@ -850,6 +854,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { } } else { + if ( empty( $is_singular ) ) { if ( empty( $restriction['_um_access_hide_from_queries'] ) ) { @@ -911,6 +916,8 @@ if ( ! class_exists( 'um\core\Access' ) ) { */ do_action( 'um_access_fix_external_post_content' ); + add_filter( 'single_template', array( &$this, 'woocommerce_template' ), 9999999, 1 ); + $filtered_posts[] = $post; continue; } elseif ( '1' == $restriction['_um_noaccess_action'] ) { @@ -941,6 +948,24 @@ if ( ! class_exists( 'um\core\Access' ) ) { } + /** + * @param string $single_template + * + * @return string + */ + function woocommerce_template( $single_template ) { + if ( ! UM()->dependencies()->woocommerce_active_check() ) { + return $single_template; + } + + if ( is_product() ) { + remove_filter( 'template_include', array( 'WC_Template_Loader', 'template_loader' ) ); + } + + return $single_template; + } + + /** * @param $content *