2013-06-06 12:27:04 +00:00
|
|
|
<?php
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2015-11-03 13:53:50 +00:00
|
|
|
* Template Loader
|
2013-09-12 13:41:02 +00:00
|
|
|
*
|
|
|
|
* @class WC_Template
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
2017-11-08 19:57:49 +00:00
|
|
|
* @author Automattic
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WC_Template_Loader.
|
2013-09-12 13:41:02 +00:00
|
|
|
*/
|
|
|
|
class WC_Template_Loader {
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2017-11-09 10:44:29 +00:00
|
|
|
/**
|
|
|
|
* Store the shop page ID.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
*/
|
|
|
|
private static $shop_page_id = 0;
|
|
|
|
|
2017-11-13 18:42:28 +00:00
|
|
|
/**
|
|
|
|
* Store whether we're processing a product inside the_content filter.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2017-11-10 20:48:45 +00:00
|
|
|
private static $in_content_filter = false;
|
|
|
|
|
2013-09-12 13:41:02 +00:00
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Hook in methods.
|
2013-09-12 13:41:02 +00:00
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function init() {
|
2017-11-09 10:44:29 +00:00
|
|
|
self::$shop_page_id = wc_get_page_id( 'shop' );
|
|
|
|
|
2017-11-10 20:48:45 +00:00
|
|
|
// Supported themes.
|
2017-11-13 20:16:44 +00:00
|
|
|
if ( current_theme_supports( 'woocommerce' ) ) {
|
2017-11-10 20:48:45 +00:00
|
|
|
add_filter( 'template_include', array( __CLASS__, 'template_loader' ) );
|
|
|
|
add_filter( 'comments_template', array( __CLASS__, 'comments_template_loader' ) );
|
2017-11-13 18:08:46 +00:00
|
|
|
} else {
|
2017-11-13 18:42:28 +00:00
|
|
|
// Unsupported themes.
|
2017-11-13 18:08:46 +00:00
|
|
|
add_action( 'template_redirect', array( __CLASS__, 'unsupported_theme_init' ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-06 12:27:04 +00:00
|
|
|
/**
|
|
|
|
* Load a template.
|
|
|
|
*
|
|
|
|
* Handles template usage so that we can use our own templates instead of the themes.
|
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* Templates are in the 'templates' folder. woocommerce looks for theme.
|
|
|
|
* overrides in /theme/woocommerce/ by default.
|
2013-06-06 12:27:04 +00:00
|
|
|
*
|
2015-11-03 13:31:20 +00:00
|
|
|
* For beginners, it also looks for a woocommerce.php template first. If the user adds.
|
|
|
|
* this to the theme (containing a woocommerce() inside) this will be used for all.
|
2013-06-06 12:27:04 +00:00
|
|
|
* woocommerce templates.
|
|
|
|
*
|
2017-11-09 10:44:29 +00:00
|
|
|
* @param string $template Template to load.
|
2013-06-06 12:27:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function template_loader( $template ) {
|
2017-11-09 10:44:29 +00:00
|
|
|
if ( is_embed() ) {
|
2016-04-25 09:27:53 +00:00
|
|
|
return $template;
|
|
|
|
}
|
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
if ( $default_file = self::get_template_loader_default_file() ) {
|
|
|
|
/**
|
|
|
|
* Filter hook to choose which files to find before WooCommerce does it's own logic.
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-12-06 11:52:15 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
$search_files = self::get_template_loader_files( $default_file );
|
|
|
|
$template = locate_template( $search_files );
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
if ( ! $template || WC_TEMPLATE_DEBUG_MODE ) {
|
|
|
|
$template = WC()->plugin_path() . '/templates/' . $default_file;
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
return $template;
|
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Get the default filename for a template.
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2016-12-06 11:52:15 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private static function get_template_loader_default_file() {
|
|
|
|
if ( is_singular( 'product' ) ) {
|
|
|
|
$default_file = 'single-product.php';
|
|
|
|
} elseif ( is_product_taxonomy() ) {
|
2017-11-14 10:39:33 +00:00
|
|
|
$object = get_queried_object();
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-05-22 09:51:40 +00:00
|
|
|
if ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
|
2017-11-14 10:39:33 +00:00
|
|
|
$default_file = 'taxonomy-' . $object->taxonomy . '.php';
|
2014-05-22 09:51:40 +00:00
|
|
|
} else {
|
2016-12-06 11:52:15 +00:00
|
|
|
$default_file = 'archive-product.php';
|
2014-05-22 09:51:40 +00:00
|
|
|
}
|
2016-12-06 11:52:15 +00:00
|
|
|
} elseif ( is_post_type_archive( 'product' ) || is_page( wc_get_page_id( 'shop' ) ) ) {
|
2017-11-09 10:44:29 +00:00
|
|
|
$default_file = current_theme_supports( 'woocommerce' ) ? 'archive-product.php' : '';
|
2016-12-06 11:52:15 +00:00
|
|
|
} else {
|
|
|
|
$default_file = '';
|
|
|
|
}
|
|
|
|
return $default_file;
|
|
|
|
}
|
2014-05-22 09:51:40 +00:00
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
/**
|
|
|
|
* Get an array of filenames to search for a given template.
|
|
|
|
*
|
2017-03-15 16:36:53 +00:00
|
|
|
* @since 3.0.0
|
2017-05-15 11:50:52 +00:00
|
|
|
* @param string $default_file The default file name.
|
2016-12-06 11:52:15 +00:00
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
private static function get_template_loader_files( $default_file ) {
|
2017-11-14 10:39:33 +00:00
|
|
|
$templates = apply_filters( 'woocommerce_template_loader_files', array(), $default_file );
|
|
|
|
$templates[] = 'woocommerce.php';
|
2016-12-06 11:52:15 +00:00
|
|
|
|
2017-09-20 14:47:30 +00:00
|
|
|
if ( is_page_template() ) {
|
2017-11-14 10:39:33 +00:00
|
|
|
$templates[] = get_page_template_slug();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( is_singular( 'product' ) ) {
|
|
|
|
$object = get_queried_object();
|
|
|
|
$name_decoded = urldecode( $object->post_name );
|
|
|
|
if ( $name_decoded !== $object->post_name ) {
|
|
|
|
$templates[] = "single-product-{$name_decoded}.php";
|
|
|
|
}
|
|
|
|
$templates[] = "single-product-{$object->post_name}.php";
|
2017-09-20 14:47:30 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 11:52:15 +00:00
|
|
|
if ( is_product_taxonomy() ) {
|
2017-11-15 09:41:26 +00:00
|
|
|
$object = get_queried_object();
|
2017-11-14 10:39:33 +00:00
|
|
|
$templates[] = 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
|
|
|
|
$templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '-' . $object->slug . '.php';
|
|
|
|
$templates[] = 'taxonomy-' . $object->taxonomy . '.php';
|
|
|
|
$templates[] = WC()->template_path() . 'taxonomy-' . $object->taxonomy . '.php';
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 10:39:33 +00:00
|
|
|
$templates[] = $default_file;
|
|
|
|
$templates[] = WC()->template_path() . $default_file;
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2017-11-14 10:39:33 +00:00
|
|
|
return array_unique( $templates );
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-01-06 15:24:47 +00:00
|
|
|
* Load comments template.
|
2013-06-06 12:27:04 +00:00
|
|
|
*
|
2017-11-08 19:57:49 +00:00
|
|
|
* @param string $template template to load.
|
2013-06-06 12:27:04 +00:00
|
|
|
* @return string
|
|
|
|
*/
|
2014-05-28 13:52:50 +00:00
|
|
|
public static function comments_template_loader( $template ) {
|
2017-11-09 10:44:29 +00:00
|
|
|
if ( get_post_type() !== 'product' ) {
|
2013-06-06 12:27:04 +00:00
|
|
|
return $template;
|
2014-10-03 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$check_dirs = array(
|
|
|
|
trailingslashit( get_stylesheet_directory() ) . WC()->template_path(),
|
|
|
|
trailingslashit( get_template_directory() ) . WC()->template_path(),
|
|
|
|
trailingslashit( get_stylesheet_directory() ),
|
|
|
|
trailingslashit( get_template_directory() ),
|
2016-08-27 02:08:49 +00:00
|
|
|
trailingslashit( WC()->plugin_path() ) . 'templates/',
|
2014-10-03 09:52:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if ( WC_TEMPLATE_DEBUG_MODE ) {
|
|
|
|
$check_dirs = array( array_pop( $check_dirs ) );
|
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
|
2014-10-03 09:52:11 +00:00
|
|
|
foreach ( $check_dirs as $dir ) {
|
|
|
|
if ( file_exists( trailingslashit( $dir ) . 'single-product-reviews.php' ) ) {
|
|
|
|
return trailingslashit( $dir ) . 'single-product-reviews.php';
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:27:04 +00:00
|
|
|
}
|
2017-11-13 18:08:46 +00:00
|
|
|
|
2017-11-30 17:58:39 +00:00
|
|
|
/**
|
|
|
|
* Unsupported theme compatibility methods.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook in methods to enhance the unsupported theme experience on pages.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
public static function unsupported_theme_init() {
|
|
|
|
if ( self::$shop_page_id ) {
|
2017-11-30 18:57:33 +00:00
|
|
|
if ( is_product_taxonomy() ) {
|
2017-11-30 17:58:39 +00:00
|
|
|
self::unsupported_theme_tax_archive_init();
|
|
|
|
} elseif ( is_product() ) {
|
|
|
|
self::unsupported_theme_product_page_init();
|
|
|
|
} else {
|
|
|
|
self::unsupported_theme_shop_page_init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook in methods to enhance the unsupported theme experience on the Shop page.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
private static function unsupported_theme_shop_page_init() {
|
|
|
|
add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_shop_content_filter' ), 10 );
|
|
|
|
add_filter( 'the_title', array( __CLASS__, 'unsupported_theme_title_filter' ), 10, 2 );
|
|
|
|
add_filter( 'comments_number', '__return_empty_string' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook in methods to enhance the unsupported theme experience on Product pages.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
private static function unsupported_theme_product_page_init() {
|
|
|
|
add_filter( 'the_content', array( __CLASS__, 'unsupported_theme_product_content_filter' ), 10 );
|
|
|
|
add_filter( 'post_thumbnail_html', array( __CLASS__, 'unsupported_theme_single_featured_image_filter' ) );
|
|
|
|
add_filter( 'woocommerce_product_tabs', array( __CLASS__, 'unsupported_theme_remove_review_tab' ) );
|
|
|
|
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
|
|
|
|
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
|
|
|
|
add_theme_support( 'wc-product-gallery-zoom' );
|
|
|
|
add_theme_support( 'wc-product-gallery-lightbox' );
|
|
|
|
add_theme_support( 'wc-product-gallery-slider' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enhance the unsupported theme experience on Product Category and Attribute pages by rendering
|
2017-11-30 18:57:33 +00:00
|
|
|
* those pages using the single template and shortcode-based content. To do this we make a dummy
|
|
|
|
* post and set a shortcode as the post content. This approach is adapted from bbPress.
|
2017-11-30 17:58:39 +00:00
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
*/
|
|
|
|
private static function unsupported_theme_tax_archive_init() {
|
|
|
|
global $wp_query, $post;
|
|
|
|
|
|
|
|
$queried_object = get_queried_object();
|
2017-12-04 15:33:42 +00:00
|
|
|
$args = self::get_current_shop_view_args();
|
|
|
|
$shortcode_args = array(
|
|
|
|
'page' => $args->page,
|
|
|
|
'columns' => $args->columns,
|
|
|
|
'rows' => $args->rows,
|
|
|
|
'orderby' => '',
|
|
|
|
'order' => '',
|
|
|
|
'paginate' => true,
|
|
|
|
'cache' => false,
|
|
|
|
);
|
2017-11-30 18:57:33 +00:00
|
|
|
|
|
|
|
if ( is_product_category() ) {
|
2017-11-30 21:43:32 +00:00
|
|
|
$shortcode_args['category'] = sanitize_title( $queried_object->slug );
|
2017-11-30 18:57:33 +00:00
|
|
|
} elseif ( taxonomy_is_product_attribute( $queried_object->taxonomy ) ) {
|
2017-11-30 21:43:32 +00:00
|
|
|
$shortcode_args['attribute'] = sanitize_title( $queried_object->taxonomy );
|
|
|
|
$shortcode_args['terms'] = sanitize_title( $queried_object->slug );
|
2017-11-30 18:57:33 +00:00
|
|
|
} elseif ( is_product_tag() ) {
|
2017-11-30 21:43:32 +00:00
|
|
|
$shortcode_args['tag'] = sanitize_title( $queried_object->slug );
|
2017-11-30 18:57:33 +00:00
|
|
|
} else {
|
2017-11-30 21:43:32 +00:00
|
|
|
// Default theme archive for all other taxonomies.
|
2017-11-30 18:57:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$shortcode = new WC_Shortcode_Products( $shortcode_args );
|
|
|
|
$shop_page = get_post( self::$shop_page_id );
|
2017-11-30 17:58:39 +00:00
|
|
|
|
|
|
|
$dummy_post_properties = array(
|
2017-11-30 18:57:33 +00:00
|
|
|
'ID' => 0,
|
|
|
|
'post_status' => 'publish',
|
2017-11-30 17:58:39 +00:00
|
|
|
'post_author' => $shop_page->post_author,
|
|
|
|
'post_parent' => 0,
|
|
|
|
'post_type' => 'page',
|
|
|
|
'post_date' => $shop_page->post_date,
|
|
|
|
'post_date_gmt' => $shop_page->post_date_gmt,
|
|
|
|
'post_modified' => $shop_page->post_modified,
|
|
|
|
'post_modified_gmt' => $shop_page->post_modified_gmt,
|
2017-11-30 18:57:33 +00:00
|
|
|
'post_content' => $shortcode->get_content(),
|
2017-11-30 21:43:32 +00:00
|
|
|
'post_title' => wc_clean( $queried_object->name ),
|
2017-11-30 17:58:39 +00:00
|
|
|
'post_excerpt' => '',
|
|
|
|
'post_content_filtered' => '',
|
|
|
|
'post_mime_type' => '',
|
|
|
|
'post_password' => '',
|
|
|
|
'post_name' => $queried_object->slug,
|
|
|
|
'guid' => '',
|
|
|
|
'menu_order' => 0,
|
|
|
|
'pinged' => '',
|
|
|
|
'to_ping' => '',
|
|
|
|
'ping_status' => '',
|
|
|
|
'comment_status' => 'closed',
|
|
|
|
'comment_count' => 0,
|
|
|
|
'filter' => 'raw',
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set the $post global.
|
|
|
|
$post = new WP_Post( (object) $dummy_post_properties );
|
|
|
|
|
|
|
|
// Copy the new post global into the main $wp_query.
|
|
|
|
$wp_query->post = $post;
|
|
|
|
$wp_query->posts = array( $post );
|
|
|
|
|
2017-11-30 18:57:33 +00:00
|
|
|
// Prevent comments form from appearing.
|
2017-11-30 17:58:39 +00:00
|
|
|
$wp_query->post_count = 1;
|
|
|
|
$wp_query->is_404 = false;
|
|
|
|
$wp_query->is_page = true;
|
|
|
|
$wp_query->is_single = true;
|
|
|
|
$wp_query->is_archive = false;
|
|
|
|
$wp_query->is_tax = false;
|
|
|
|
|
2017-11-30 18:57:33 +00:00
|
|
|
// Prepare everything for rendering.
|
2017-11-30 17:58:39 +00:00
|
|
|
setup_postdata( $post );
|
|
|
|
remove_all_filters( 'the_content' );
|
|
|
|
remove_all_filters( 'the_excerpt' );
|
2017-11-30 18:57:33 +00:00
|
|
|
add_filter( 'template_include', array( __CLASS__, 'force_single_template_filter' ) );
|
|
|
|
}
|
2017-11-30 17:58:39 +00:00
|
|
|
|
2017-11-30 18:57:33 +00:00
|
|
|
/**
|
|
|
|
* Force the loading of one of the single templates instead of whatever template was about to be loaded.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @param string $template Path to template.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function force_single_template_filter( $template ) {
|
|
|
|
$possible_templates = array(
|
|
|
|
'page',
|
|
|
|
'single',
|
|
|
|
'singular',
|
|
|
|
'index',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ( $possible_templates as $possible_template ) {
|
|
|
|
$path = get_query_template( $possible_template );
|
|
|
|
if ( $path ) {
|
|
|
|
return $path;
|
2017-11-30 17:58:39 +00:00
|
|
|
}
|
2017-11-30 18:57:33 +00:00
|
|
|
}
|
2017-11-30 17:58:39 +00:00
|
|
|
|
2017-11-30 18:57:33 +00:00
|
|
|
return $template;
|
2017-11-30 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get information about the current shop page view.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private static function get_current_shop_view_args() {
|
|
|
|
return (object) array(
|
|
|
|
'page' => absint( max( 1, absint( get_query_var( 'paged' ) ) ) ),
|
|
|
|
'columns' => wc_get_default_products_per_row(),
|
|
|
|
'rows' => wc_get_default_product_rows_per_page(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-13 18:08:46 +00:00
|
|
|
/**
|
|
|
|
* Filter the title and insert WooCommerce content on the shop page.
|
|
|
|
*
|
|
|
|
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @param string $title Existing title.
|
|
|
|
* @param int $id ID of the post being filtered.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function unsupported_theme_title_filter( $title, $id ) {
|
|
|
|
if ( ! current_theme_supports( 'woocommerce' ) && is_page( self::$shop_page_id ) && $id === self::$shop_page_id ) {
|
|
|
|
$args = self::get_current_shop_view_args();
|
|
|
|
$title_suffix = array();
|
|
|
|
|
|
|
|
if ( $args->page > 1 ) {
|
|
|
|
$title_suffix[] = sprintf( esc_html__( 'Page %d', 'woocommerce' ), $args->page );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $title_suffix ) {
|
|
|
|
$title = $title . ' – ' . implode( ', ', $title_suffix );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the content and insert WooCommerce content on the shop page.
|
|
|
|
*
|
|
|
|
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @param string $content Existing post content.
|
|
|
|
* @return string
|
|
|
|
*/
|
2017-11-30 17:58:39 +00:00
|
|
|
public static function unsupported_theme_shop_content_filter( $content ) {
|
2017-11-13 18:08:46 +00:00
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
if ( current_theme_supports( 'woocommerce' ) || ! is_main_query() ) {
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$in_content_filter = true;
|
|
|
|
|
|
|
|
// Remove the filter we're in to avoid nested calls.
|
|
|
|
remove_filter( 'the_content', array( __CLASS__, 'the_content_filter' ) );
|
|
|
|
|
|
|
|
// Unsupported theme shop page.
|
|
|
|
if ( is_page( self::$shop_page_id ) ) {
|
|
|
|
$args = self::get_current_shop_view_args();
|
|
|
|
$shortcode = new WC_Shortcode_Products(
|
|
|
|
array_merge(
|
|
|
|
wc()->query->get_catalog_ordering_args(),
|
|
|
|
array(
|
|
|
|
'page' => $args->page,
|
|
|
|
'columns' => $args->columns,
|
|
|
|
'rows' => $args->rows,
|
|
|
|
'orderby' => '',
|
|
|
|
'order' => '',
|
|
|
|
'paginate' => true,
|
|
|
|
'cache' => false,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
'products' );
|
|
|
|
|
|
|
|
// Allow queries to run e.g. layered nav.
|
|
|
|
add_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
|
|
|
|
|
|
|
|
$content = $content . $shortcode->get_content();
|
|
|
|
|
|
|
|
// Remove actions and self to avoid nested calls.
|
|
|
|
remove_action( 'pre_get_posts', array( wc()->query, 'product_query' ) );
|
2017-11-30 17:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self::$in_content_filter = false;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter the content and insert WooCommerce content on the shop page.
|
|
|
|
*
|
|
|
|
* For non-WC themes, this will setup the main shop page to be shortcode based to improve default appearance.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @param string $content Existing post content.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function unsupported_theme_product_content_filter( $content ) {
|
|
|
|
global $wp_query;
|
|
|
|
|
|
|
|
if ( current_theme_supports( 'woocommerce' ) || ! is_main_query() ) {
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
self::$in_content_filter = true;
|
|
|
|
|
|
|
|
// Remove the filter we're in to avoid nested calls.
|
|
|
|
remove_filter( 'the_content', array( __CLASS__, 'the_content_filter' ) );
|
2017-11-13 18:08:46 +00:00
|
|
|
|
2017-11-30 17:58:39 +00:00
|
|
|
if ( is_product() ) {
|
2017-11-13 18:36:58 +00:00
|
|
|
$content = do_shortcode( '[product_page id="' . get_the_ID() . '" show_title=0]' );
|
2017-11-13 18:08:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self::$in_content_filter = false;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevent the main featured image on product pages because there will be another featured image
|
|
|
|
* in the gallery.
|
|
|
|
*
|
|
|
|
* @since 3.3.0
|
|
|
|
* @param string $html Img element HTML.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public static function unsupported_theme_single_featured_image_filter( $html ) {
|
|
|
|
if ( self::$in_content_filter || ! is_product() || ! is_main_query() ) {
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the Review tab and just use the regular comment form.
|
|
|
|
*
|
|
|
|
* @param array $tabs Tab info.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function unsupported_theme_remove_review_tab( $tabs ) {
|
|
|
|
unset( $tabs['reviews'] );
|
|
|
|
return $tabs;
|
|
|
|
}
|
2013-08-06 17:04:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 19:56:24 +00:00
|
|
|
add_action( 'init', array( 'WC_Template_Loader', 'init' ) );
|