From c3689134d0656ea700ee444c88fd30fdfa9309d7 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Mon, 6 Nov 2017 13:46:50 -0800 Subject: [PATCH] Underscores wrappers --- includes/wc-template-functions.php | 38 ++++++++++++++++++++++++++++++ templates/global/wrapper-end.php | 7 ++++-- templates/global/wrapper-start.php | 7 ++++-- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index f132b75e995..acb928bfc71 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2728,3 +2728,41 @@ function wc_page_noindex() { } } add_action( 'wp_head', 'wc_page_noindex' ); + +/** + * Get a slug identifying the current theme. + * + * @since 3.3.0 + * @return string + */ +function wc_get_theme_slug_for_templates() { + /** + * @hooked wc_check_for_underscores_theme + * @since 3.3.0 + */ + $template = apply_filters( 'woocommerce_theme_slug_for_templates', get_option( 'template' ) ); + + return $template; +} + +/** + * Treat all themes that don't formally support WooCommerce and are based on Underscores as one 'underscores' theme for templates. + * + * @since 3.3.0 + * @param string $template + * @return string + */ +function wc_check_for_underscores_theme( $template ) { + if ( ! current_theme_supports( 'woocommerce' ) && ! in_array( $template, wc_get_core_supported_themes() ) ) { + $stylesheet = get_stylesheet_directory() . '/style.css'; + if( file_exists( $stylesheet ) ) { + $stylesheet_contents = file_get_contents( $stylesheet ); + if ( stripos( $stylesheet_contents, 'underscores' ) ) { + return 'underscores'; + } + } + } + + return $template; +} +add_filter( 'woocommerce_theme_slug_for_templates', 'wc_check_for_underscores_theme' ); diff --git a/templates/global/wrapper-end.php b/templates/global/wrapper-end.php index 572b667c333..fd4cac835bd 100644 --- a/templates/global/wrapper-end.php +++ b/templates/global/wrapper-end.php @@ -13,14 +13,14 @@ * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 3.3.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -$template = get_option( 'template' ); +$template = wc_get_theme_slug_for_templates(); switch ( $template ) { case 'twentyeleven' : @@ -44,6 +44,9 @@ switch ( $template ) { case 'twentysixteen' : echo ''; break; + case 'underscores' : + echo ''; + break; default : echo ''; break; diff --git a/templates/global/wrapper-start.php b/templates/global/wrapper-start.php index 55117b0ce15..3ed9bed3926 100644 --- a/templates/global/wrapper-start.php +++ b/templates/global/wrapper-start.php @@ -13,14 +13,14 @@ * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates - * @version 1.6.4 + * @version 3.3.0 */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } -$template = get_option( 'template' ); +$template = wc_get_theme_slug_for_templates(); switch ( $template ) { case 'twentyeleven' : @@ -41,6 +41,9 @@ switch ( $template ) { case 'twentysixteen' : echo '
'; break; + case 'underscores' : + echo '
'; + break; default : echo '
'; break;