first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,192 @@
<?php
/**
* Storefront WooCommerce Adjacent Products Class
*
* @package storefront
* @since 2.4.3
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Storefront_WooCommerce_Adjacent_Products' ) ) :
/**
* The Storefront WooCommerce Adjacent Products Class
*/
class Storefront_WooCommerce_Adjacent_Products {
/**
* The current product ID.
*
* @var int|null
*/
private $current_product = null;
/**
* Whether post should be in a same taxonomy term.
*
* @var bool
*/
private $in_same_term = false;
/**
* List of excluded term IDs.
*
* @var string
*/
private $excluded_terms = '';
/**
* Taxonomy slug.
*
* @var string
*/
private $taxonomy = 'product_cat';
/**
* Whether to retrieve previous product.
*
* @var bool
*/
private $previous = false;
/**
* Constructor.
*
* @since 2.4.3
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
* @param bool $previous Optional. Whether to retrieve previous product. Default false.
*/
public function __construct( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat', $previous = false ) {
$this->in_same_term = $in_same_term;
$this->excluded_terms = $excluded_terms;
$this->taxonomy = $taxonomy;
$this->previous = $previous;
}
/**
* Get adjacent product or circle back to the first/last valid product.
*
* @since 2.4.3
*
* @return WC_Product|false Product object if successful. False if no valid product is found.
*/
public function get_product() {
global $post;
$product = false;
$this->current_product = $post->ID;
// Try to get a valid product via `get_adjacent_post()`.
while ( $adjacent = $this->get_adjacent() ) {
$product = wc_get_product( $adjacent->ID );
if ( $product && $product->is_visible() ) {
break;
}
$product = false;
$this->current_product = $adjacent->ID;
}
if ( $product ) {
return $product;
}
// No valid product found; Query WC for first/last product.
$product = $this->query_wc();
if ( $product ) {
return $product;
}
return false;
}
/**
* Get adjacent post.
*
* @since 2.4.3
*
* @return WP_POST|false Post object if successful. False if no valid post is found.
*/
private function get_adjacent() {
global $post;
$direction = $this->previous ? 'previous' : 'next';
add_filter( 'get_' . $direction . '_post_where', array( $this, 'filter_post_where' ) );
$adjacent = get_adjacent_post( $this->in_same_term, $this->excluded_terms, $this->previous, $this->taxonomy );
remove_filter( 'get_' . $direction . '_post_where', array( $this, 'filter_post_where' ) );
return $adjacent;
}
/**
* Filters the WHERE clause in the SQL for an adjacent post query, replacing the
* date with date of the next post to consider.
*
* @since 2.4.3
*
* @param string $where The `WHERE` clause in the SQL.
* @return WP_POST|false Post object if successful. False if no valid post is found.
*/
public function filter_post_where( $where ) {
global $post;
$new = get_post( $this->current_product );
$where = str_replace( $post->post_date, $new->post_date, $where );
return $where;
}
/**
* Query WooCommerce for either the first or last products.
*
* @since 2.4.3
*
* @return WC_Product|false Post object if successful. False if no valid post is found.
*/
private function query_wc() {
global $post;
$args = array(
'limit' => 2,
'visibility' => 'catalog',
'exclude' => array( $post->ID ),
'orderby' => 'date',
);
if ( ! $this->previous ) {
$args['order'] = 'ASC';
}
if ( $this->in_same_term ) {
$terms = get_the_terms( $post->ID, $this->taxonomy );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$args['category'] = wp_list_pluck( $terms, 'slug' );
}
}
$products = wc_get_products( apply_filters( 'storefront_woocommerce_adjacent_query_args', $args ) );
// At least 2 results are required, otherwise previous/next will be the same.
if ( ! empty( $products ) && count( $products ) >= 2 ) {
return $products[0];
}
return false;
}
}
endif;

View File

@@ -0,0 +1,331 @@
<?php
/**
* Storefront WooCommerce Customizer Class
*
* @package storefront
* @since 2.4.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Storefront_WooCommerce_Customizer' ) ) :
/**
* The Storefront Customizer class
*/
class Storefront_WooCommerce_Customizer extends Storefront_Customizer {
/**
* Setup class.
*
* @since 2.4.0
* @return void
*/
public function __construct() {
add_action( 'customize_register', array( $this, 'customize_register' ), 10 );
add_action( 'wp_enqueue_scripts', array( $this, 'add_customizer_css' ), 130 );
add_filter( 'storefront_setting_default_values', array( $this, 'setting_default_values' ) );
}
/**
* Returns an array of the desired default Storefront Options
*
* @param array $defaults array of default options.
* @since 2.4.0
* @return array
*/
public function setting_default_values( $defaults = array() ) {
$defaults['storefront_sticky_add_to_cart'] = true;
$defaults['storefront_product_pagination'] = true;
return $defaults;
}
/**
* Add postMessage support for site title and description for the Theme Customizer along with several other settings.
*
* @param WP_Customize_Manager $wp_customize Theme Customizer object.
* @since 2.4.0
*/
public function customize_register( $wp_customize ) {
/**
* Product Page
*/
$wp_customize->add_section(
'storefront_single_product_page', array(
'title' => __( 'Product Page', 'storefront' ),
'priority' => 60,
)
);
$wp_customize->add_setting(
'storefront_product_pagination', array(
'default' => apply_filters( 'storefront_default_product_pagination', true ),
'sanitize_callback' => 'wp_validate_boolean',
)
);
$wp_customize->add_setting(
'storefront_sticky_add_to_cart', array(
'default' => apply_filters( 'storefront_default_sticky_add_to_cart', true ),
'sanitize_callback' => 'wp_validate_boolean',
)
);
$wp_customize->add_control(
'storefront_sticky_add_to_cart', array(
'type' => 'checkbox',
'section' => 'storefront_single_product_page',
'label' => __( 'Sticky Add-To-Cart', 'storefront' ),
'description' => __( 'A small content bar at the top of the browser window which includes relevant product information and an add-to-cart button. It slides into view once the standard add-to-cart button has scrolled out of view.', 'storefront' ),
'priority' => 10,
)
);
$wp_customize->add_control(
'storefront_product_pagination', array(
'type' => 'checkbox',
'section' => 'storefront_single_product_page',
'label' => __( 'Product Pagination', 'storefront' ),
'description' => __( 'Displays next and previous links on product pages. A product thumbnail is displayed with the title revealed on hover.', 'storefront' ),
'priority' => 20,
)
);
}
/**
* Get Customizer css.
*
* @see get_storefront_theme_mods()
* @since 2.4.0
* @return string $styles the css
*/
public function get_css() {
$storefront_theme_mods = $this->get_storefront_theme_mods();
$brighten_factor = apply_filters( 'storefront_brighten_factor', 25 );
$darken_factor = apply_filters( 'storefront_darken_factor', -25 );
$styles = '
a.cart-contents,
.site-header-cart .widget_shopping_cart a {
color: ' . $storefront_theme_mods['header_link_color'] . ';
}
a.cart-contents:hover,
.site-header-cart .widget_shopping_cart a:hover,
.site-header-cart:hover > li > a {
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_link_color'], 65 ) . ';
}
table.cart td.product-remove,
table.cart td.actions {
border-top-color: ' . $storefront_theme_mods['background_color'] . ';
}
.storefront-handheld-footer-bar ul li.cart .count {
background-color: ' . $storefront_theme_mods['header_link_color'] . ';
color: ' . $storefront_theme_mods['header_background_color'] . ';
border-color: ' . $storefront_theme_mods['header_background_color'] . ';
}
.woocommerce-tabs ul.tabs li.active a,
ul.products li.product .price,
.onsale,
.wc-block-grid__product-onsale,
.widget_search form:before,
.widget_product_search form:before {
color: ' . $storefront_theme_mods['text_color'] . ';
}
.woocommerce-breadcrumb a,
a.woocommerce-review-link,
.product_meta a {
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['text_color'], 5 ) . ';
}
.wc-block-grid__product-onsale,
.onsale {
border-color: ' . $storefront_theme_mods['text_color'] . ';
}
.star-rating span:before,
.quantity .plus, .quantity .minus,
p.stars a:hover:after,
p.stars a:after,
.star-rating span:before,
#payment .payment_methods li input[type=radio]:first-child:checked+label:before {
color: ' . $storefront_theme_mods['accent_color'] . ';
}
.widget_price_filter .ui-slider .ui-slider-range,
.widget_price_filter .ui-slider .ui-slider-handle {
background-color: ' . $storefront_theme_mods['accent_color'] . ';
}
.order_details {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ';
}
.order_details > li {
border-bottom: 1px dotted ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -28 ) . ';
}
.order_details:before,
.order_details:after {
background: -webkit-linear-gradient(transparent 0,transparent 0),-webkit-linear-gradient(135deg,' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ' 33.33%,transparent 33.33%),-webkit-linear-gradient(45deg,' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -7 ) . ' 33.33%,transparent 33.33%)
}
#order_review {
background-color: ' . $storefront_theme_mods['background_color'] . ';
}
#payment .payment_methods > li .payment_box,
#payment .place-order {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -5 ) . ';
}
#payment .payment_methods > li:not(.woocommerce-notice) {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -10 ) . ';
}
#payment .payment_methods > li:not(.woocommerce-notice):hover {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], -15 ) . ';
}
.woocommerce-pagination .page-numbers li .page-numbers.current {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['background_color'], $darken_factor ) . ';
color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['text_color'], -10 ) . ';
}
.wc-block-grid__product-onsale,
.onsale,
.woocommerce-pagination .page-numbers li .page-numbers:not(.current) {
color: ' . $storefront_theme_mods['text_color'] . ';
}
p.stars a:before,
p.stars a:hover~a:before,
p.stars.selected a.active~a:before {
color: ' . $storefront_theme_mods['text_color'] . ';
}
p.stars.selected a.active:before,
p.stars:hover a:before,
p.stars.selected a:not(.active):before,
p.stars.selected a.active:before {
color: ' . $storefront_theme_mods['accent_color'] . ';
}
.single-product div.product .woocommerce-product-gallery .woocommerce-product-gallery__trigger {
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
.single-product div.product .woocommerce-product-gallery .woocommerce-product-gallery__trigger:hover {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
.button.added_to_cart:focus,
.button.wc-forward:focus {
outline-color: ' . $storefront_theme_mods['accent_color'] . ';
}
.added_to_cart,
.site-header-cart .widget_shopping_cart a.button,
.wc-block-grid__products .wc-block-grid__product .wp-block-button__link {
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
border-color: ' . $storefront_theme_mods['button_background_color'] . ';
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
.added_to_cart:hover,
.site-header-cart .widget_shopping_cart a.button:hover,
.wc-block-grid__products .wc-block-grid__product .wp-block-button__link:hover {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_background_color'], $darken_factor ) . ';
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
.added_to_cart.alt, .added_to_cart, .widget a.button.checkout {
background-color: ' . $storefront_theme_mods['button_alt_background_color'] . ';
border-color: ' . $storefront_theme_mods['button_alt_background_color'] . ';
color: ' . $storefront_theme_mods['button_alt_text_color'] . ';
}
.added_to_cart.alt:hover, .added_to_cart:hover, .widget a.button.checkout:hover {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_alt_background_color'], $darken_factor ) . ';
border-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['button_alt_background_color'], $darken_factor ) . ';
color: ' . $storefront_theme_mods['button_alt_text_color'] . ';
}
.button.loading {
color: ' . $storefront_theme_mods['button_background_color'] . ';
}
.button.loading:hover {
background-color: ' . $storefront_theme_mods['button_background_color'] . ';
}
.button.loading:after {
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
@media screen and ( min-width: 768px ) {
.site-header-cart .widget_shopping_cart,
.site-header .product_list_widget li .quantity {
color: ' . $storefront_theme_mods['header_text_color'] . ';
}
.site-header-cart .widget_shopping_cart .buttons,
.site-header-cart .widget_shopping_cart .total {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_background_color'], -10 ) . ';
}
.site-header-cart .widget_shopping_cart {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['header_background_color'], -15 ) . ';
}
}';
if ( ! class_exists( 'Storefront_Product_Pagination' ) ) {
$styles .= '
.storefront-product-pagination a {
color: ' . $storefront_theme_mods['text_color'] . ';
background-color: ' . $storefront_theme_mods['background_color'] . ';
}';
}
if ( ! class_exists( 'Storefront_Sticky_Add_to_Cart' ) ) {
$styles .= '
.storefront-sticky-add-to-cart {
color: ' . $storefront_theme_mods['text_color'] . ';
background-color: ' . $storefront_theme_mods['background_color'] . ';
}
.storefront-sticky-add-to-cart a:not(.button) {
color: ' . $storefront_theme_mods['header_link_color'] . ';
}';
}
return apply_filters( 'storefront_customizer_woocommerce_css', $styles );
}
/**
* Add CSS in <head> for styles handled by the theme customizer
*
* @since 2.4.0
* @return void
*/
public function add_customizer_css() {
wp_add_inline_style( 'storefront-woocommerce-style', $this->get_css() );
}
}
endif;
return new Storefront_WooCommerce_Customizer();

View File

@@ -0,0 +1,532 @@
<?php
/**
* Storefront WooCommerce Class
*
* @package storefront
* @since 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Storefront_WooCommerce' ) ) :
/**
* The Storefront WooCommerce Integration class
*/
class Storefront_WooCommerce {
/**
* Setup class.
*
* @since 1.0
*/
public function __construct() {
add_action( 'after_setup_theme', array( $this, 'setup' ) );
add_filter( 'body_class', array( $this, 'woocommerce_body_class' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_scripts' ), 20 );
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_args' ) );
add_filter( 'woocommerce_product_thumbnails_columns', array( $this, 'thumbnail_columns' ) );
add_filter( 'woocommerce_breadcrumb_defaults', array( $this, 'change_breadcrumb_delimiter' ) );
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.5', '<' ) ) {
add_action( 'wp_footer', array( $this, 'star_rating_script' ) );
}
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
add_filter( 'loop_shop_per_page', array( $this, 'products_per_page' ) );
}
// Integrations.
add_action( 'storefront_woocommerce_setup', array( $this, 'setup_integrations' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_integrations_scripts' ), 99 );
add_action( 'wp_enqueue_scripts', array( $this, 'add_customizer_css' ), 140 );
}
/**
* Sets up theme defaults and registers support for various WooCommerce features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* @since 2.4.0
* @return void
*/
public function setup() {
add_theme_support(
'woocommerce', apply_filters(
'storefront_woocommerce_args', array(
'single_image_width' => 416,
'thumbnail_image_width' => 324,
'product_grid' => array(
'default_columns' => 3,
'default_rows' => 4,
'min_columns' => 1,
'max_columns' => 6,
'min_rows' => 1,
),
)
)
);
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
/**
* Add 'storefront_woocommerce_setup' action.
*
* @since 2.4.0
*/
do_action( 'storefront_woocommerce_setup' );
}
/**
* Add CSS in <head> for styles handled by the theme customizer
* If the Customizer is active pull in the raw css. Otherwise pull in the prepared theme_mods if they exist.
*
* @since 2.1.0
* @return void
*/
public function add_customizer_css() {
wp_add_inline_style( 'storefront-woocommerce-style', $this->get_woocommerce_extension_css() );
}
/**
* Assign styles to individual theme mod.
*
* @deprecated 2.3.1
* @since 2.1.0
* @return void
*/
public function set_storefront_style_theme_mods() {
if ( function_exists( 'wc_deprecated_function' ) ) {
wc_deprecated_function( __FUNCTION__, '2.3.1' );
} else {
_deprecated_function( __FUNCTION__, '2.3.1' );
}
}
/**
* Add WooCommerce specific classes to the body tag
*
* @param array $classes css classes applied to the body tag.
* @return array $classes modified to include 'woocommerce-active' class
*/
public function woocommerce_body_class( $classes ) {
$classes[] = 'woocommerce-active';
// Remove `no-wc-breadcrumb` body class.
$key = array_search( 'no-wc-breadcrumb', $classes, true );
if ( false !== $key ) {
unset( $classes[ $key ] );
}
return $classes;
}
/**
* WooCommerce specific scripts & stylesheets
*
* @since 1.0.0
*/
public function woocommerce_scripts() {
global $storefront_version;
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
wp_enqueue_style( 'storefront-woocommerce-style', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce.css', array(), $storefront_version );
wp_style_add_data( 'storefront-woocommerce-style', 'rtl', 'replace' );
wp_register_script( 'storefront-header-cart', get_template_directory_uri() . '/assets/js/woocommerce/header-cart' . $suffix . '.js', array(), $storefront_version, true );
wp_enqueue_script( 'storefront-header-cart' );
wp_enqueue_script( 'storefront-handheld-footer-bar', get_template_directory_uri() . '/assets/js/footer' . $suffix . '.js', array(), $storefront_version, true );
if ( ! class_exists( 'Storefront_Sticky_Add_to_Cart' ) && is_product() ) {
wp_register_script( 'storefront-sticky-add-to-cart', get_template_directory_uri() . '/assets/js/sticky-add-to-cart' . $suffix . '.js', array(), $storefront_version, true );
}
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
wp_enqueue_style( 'storefront-woocommerce-legacy', get_template_directory_uri() . '/assets/css/woocommerce/woocommerce-legacy.css', array(), $storefront_version );
wp_style_add_data( 'storefront-woocommerce-legacy', 'rtl', 'replace' );
}
}
/**
* Star rating backwards compatibility script (WooCommerce <2.5).
*
* @since 1.6.0
*/
public function star_rating_script() {
if ( is_product() ) {
?>
<script type="text/javascript">
var starsEl = document.querySelector( '#respond p.stars' );
if ( starsEl ) {
starsEl.addEventListener( 'click', function( event ) {
if ( event.target.tagName === 'A' ) {
starsEl.classList.add( 'selected' );
}
} );
}
</script>
<?php
}
}
/**
* Related Products Args
*
* @param array $args related products args.
* @since 1.0.0
* @return array $args related products args
*/
public function related_products_args( $args ) {
$args = apply_filters(
'storefront_related_products_args', array(
'posts_per_page' => 3,
'columns' => 3,
)
);
return $args;
}
/**
* Product gallery thumbnail columns
*
* @return integer number of columns
* @since 1.0.0
*/
public function thumbnail_columns() {
$columns = 4;
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$columns = 5;
}
return intval( apply_filters( 'storefront_product_thumbnail_columns', $columns ) );
}
/**
* Products per page
*
* @return integer number of products
* @since 1.0.0
*/
public function products_per_page() {
return intval( apply_filters( 'storefront_products_per_page', 12 ) );
}
/**
* Query WooCommerce Extension Activation.
*
* @param string $extension Extension class name.
* @return boolean
*/
public function is_woocommerce_extension_activated( $extension = 'WC_Bookings' ) {
return class_exists( $extension ) ? true : false;
}
/**
* Remove the breadcrumb delimiter
*
* @param array $defaults The breadcrumb defaults.
* @return array The breadcrumb defaults.
* @since 2.2.0
*/
public function change_breadcrumb_delimiter( $defaults ) {
$defaults['delimiter'] = '<span class="breadcrumb-separator"> / </span>';
$defaults['wrap_before'] = '<div class="storefront-breadcrumb"><div class="col-full"><nav class="woocommerce-breadcrumb">';
$defaults['wrap_after'] = '</nav></div></div>';
return $defaults;
}
/**
* Integration Styles & Scripts
*
* @return void
*/
public function woocommerce_integrations_scripts() {
global $storefront_version;
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
/**
* Bookings
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
wp_enqueue_style( 'storefront-woocommerce-bookings-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/bookings.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-bookings-style', 'rtl', 'replace' );
}
/**
* Brands
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Brands' ) ) {
wp_enqueue_style( 'storefront-woocommerce-brands-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/brands.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-brands-style', 'rtl', 'replace' );
wp_enqueue_script( 'storefront-woocommerce-brands', get_template_directory_uri() . '/assets/js/woocommerce/extensions/brands' . $suffix . '.js', array(), $storefront_version, true );
}
/**
* Wishlists
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Wishlists_Wishlist' ) ) {
wp_enqueue_style( 'storefront-woocommerce-wishlists-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/wishlists.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-wishlists-style', 'rtl', 'replace' );
}
/**
* AJAX Layered Nav
*/
if ( $this->is_woocommerce_extension_activated( 'SOD_Widget_Ajax_Layered_Nav' ) ) {
wp_enqueue_style( 'storefront-woocommerce-ajax-layered-nav-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/ajax-layered-nav.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-ajax-layered-nav-style', 'rtl', 'replace' );
}
/**
* Variation Swatches
*/
if ( $this->is_woocommerce_extension_activated( 'WC_SwatchesPlugin' ) ) {
wp_enqueue_style( 'storefront-woocommerce-variation-swatches-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/variation-swatches.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-variation-swatches-style', 'rtl', 'replace' );
}
/**
* Composite Products
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Composite_Products' ) ) {
wp_enqueue_style( 'storefront-woocommerce-composite-products-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/composite-products.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-composite-products-style', 'rtl', 'replace' );
}
/**
* WooCommerce Photography
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Photography' ) ) {
wp_enqueue_style( 'storefront-woocommerce-photography-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/photography.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-photography-style', 'rtl', 'replace' );
}
/**
* Product Reviews Pro
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
wp_enqueue_style( 'storefront-woocommerce-product-reviews-pro-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/product-reviews-pro.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-product-reviews-pro-style', 'rtl', 'replace' );
}
/**
* WooCommerce Smart Coupons
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
wp_enqueue_style( 'storefront-woocommerce-smart-coupons-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/smart-coupons.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-smart-coupons-style', 'rtl', 'replace' );
}
/**
* WooCommerce Deposits
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Deposits' ) ) {
wp_enqueue_style( 'storefront-woocommerce-deposits-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/deposits.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-deposits-style', 'rtl', 'replace' );
}
/**
* WooCommerce Product Bundles
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Bundles' ) ) {
wp_enqueue_style( 'storefront-woocommerce-bundles-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/bundles.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-bundles-style', 'rtl', 'replace' );
}
/**
* WooCommerce Multiple Shipping Addresses
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Ship_Multiple' ) ) {
wp_enqueue_style( 'storefront-woocommerce-sma-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/ship-multiple-addresses.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-sma-style', 'rtl', 'replace' );
}
/**
* WooCommerce Advanced Product Labels
*/
if ( $this->is_woocommerce_extension_activated( 'Woocommerce_Advanced_Product_Labels' ) ) {
wp_enqueue_style( 'storefront-woocommerce-apl-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/advanced-product-labels.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-apl-style', 'rtl', 'replace' );
}
/**
* WooCommerce Mix and Match
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Mix_and_Match' ) ) {
wp_enqueue_style( 'storefront-woocommerce-mix-and-match-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/mix-and-match.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-mix-and-match-style', 'rtl', 'replace' );
}
/**
* WooCommerce Memberships
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Memberships' ) ) {
wp_enqueue_style( 'storefront-woocommerce-memberships-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/memberships.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-memberships-style', 'rtl', 'replace' );
}
/**
* WooCommerce Quick View
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Quick_View' ) ) {
wp_enqueue_style( 'storefront-woocommerce-quick-view-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/quick-view.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-quick-view-style', 'rtl', 'replace' );
}
/**
* Checkout Add Ons
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Checkout_Add_Ons' ) ) {
add_filter( 'storefront_sticky_order_review', '__return_false' );
}
/**
* WooCommerce Product Recommendations
*/
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Recommendations' ) ) {
wp_enqueue_style( 'storefront-woocommerce-product-recommendations-style', get_template_directory_uri() . '/assets/css/woocommerce/extensions/product-recommendations.css', 'storefront-woocommerce-style', $storefront_version );
wp_style_add_data( 'storefront-woocommerce-product-recommendations-style', 'rtl', 'replace' );
}
}
/**
* Get extension css.
*
* @see get_storefront_theme_mods()
* @return array $styles the css
*/
public function get_woocommerce_extension_css() {
global $storefront;
if ( ! is_object( $storefront ) ||
! property_exists( $storefront, 'customizer' ) ||
! is_a( $storefront->customizer, 'Storefront_Customizer' ) ||
! method_exists( $storefront->customizer, 'get_storefront_theme_mods' ) ) {
return apply_filters( 'storefront_customizer_woocommerce_extension_css', '' );
}
$storefront_theme_mods = $storefront->customizer->get_storefront_theme_mods();
$woocommerce_extension_style = '';
if ( $this->is_woocommerce_extension_activated( 'WC_Bookings' ) ) {
$woocommerce_extension_style .= '
.wc-bookings-date-picker .ui-datepicker td.bookable a {
background-color: ' . $storefront_theme_mods['accent_color'] . ' !important;
}
.wc-bookings-date-picker .ui-datepicker td.bookable a.ui-state-default {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['accent_color'], -10 ) . ' !important;
}
.wc-bookings-date-picker .ui-datepicker td.bookable a.ui-state-active {
background-color: ' . storefront_adjust_color_brightness( $storefront_theme_mods['accent_color'], -50 ) . ' !important;
}
';
}
if ( $this->is_woocommerce_extension_activated( 'WC_Product_Reviews_Pro' ) ) {
$woocommerce_extension_style .= '
.woocommerce #reviews .product-rating .product-rating-details table td.rating-graph .bar,
.woocommerce-page #reviews .product-rating .product-rating-details table td.rating-graph .bar {
background-color: ' . $storefront_theme_mods['text_color'] . ' !important;
}
.woocommerce #reviews .contribution-actions .feedback,
.woocommerce-page #reviews .contribution-actions .feedback,
.star-rating-selector:not(:checked) label.checkbox {
color: ' . $storefront_theme_mods['text_color'] . ';
}
.woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
.woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
.star-rating-selector:not(:checked) input:checked ~ label.checkbox,
.star-rating-selector:not(:checked) label.checkbox:hover ~ label.checkbox,
.star-rating-selector:not(:checked) label.checkbox:hover,
.woocommerce #reviews #comments ol.commentlist li .contribution-actions a,
.woocommerce-page #reviews #comments ol.commentlist li .contribution-actions a,
.woocommerce #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before,
.woocommerce-page #reviews .form-contribution .attachment-type:not(:checked) label.checkbox:before {
color: ' . $storefront_theme_mods['accent_color'] . ' !important;
}';
}
if ( $this->is_woocommerce_extension_activated( 'WC_Smart_Coupons' ) ) {
$woocommerce_extension_style .= '
.coupon-container {
background-color: ' . $storefront_theme_mods['button_background_color'] . ' !important;
}
.coupon-content {
border-color: ' . $storefront_theme_mods['button_text_color'] . ' !important;
color: ' . $storefront_theme_mods['button_text_color'] . ';
}
.sd-buttons-transparent.woocommerce .coupon-content,
.sd-buttons-transparent.woocommerce-page .coupon-content {
border-color: ' . $storefront_theme_mods['button_background_color'] . ' !important;
}';
}
return apply_filters( 'storefront_customizer_woocommerce_extension_css', $woocommerce_extension_style );
}
/*
|--------------------------------------------------------------------------
| Integrations.
|--------------------------------------------------------------------------
*/
/**
* Sets up integrations.
*
* @since 2.3.4
*
* @return void
*/
public function setup_integrations() {
if ( $this->is_woocommerce_extension_activated( 'WC_Bundles' ) ) {
add_filter( 'woocommerce_bundled_table_item_js_enqueued', '__return_true' );
add_filter( 'woocommerce_bundles_group_mode_options_data', array( $this, 'bundles_group_mode_options_data' ) );
}
if ( $this->is_woocommerce_extension_activated( 'WC_Composite_Products' ) ) {
add_filter( 'woocommerce_composited_table_item_js_enqueued', '__return_true' );
add_filter( 'woocommerce_display_composite_container_cart_item_data', '__return_true' );
}
}
/**
* Add "Includes" meta to parent cart items.
* Displayed only on handheld/mobile screens.
*
* @since 2.3.4
*
* @param array $group_mode_data Group mode data.
* @return array
*/
public function bundles_group_mode_options_data( $group_mode_data ) {
$group_mode_data['parent']['features'][] = 'parent_cart_item_meta';
return $group_mode_data;
}
}
endif;
return new Storefront_WooCommerce();

View File

@@ -0,0 +1,49 @@
<?php
/**
* Storefront WooCommerce functions.
*
* @package storefront
*/
/**
* Checks if the current page is a product archive
*
* @return boolean
*/
function storefront_is_product_archive() {
if ( is_shop() || is_product_taxonomy() || is_product_category() || is_product_tag() ) {
return true;
} else {
return false;
}
}
/**
* Retrieves the previous product.
*
* @since 2.4.3
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
* @return WC_Product|false Product object if successful. False if no valid product is found.
*/
function storefront_get_previous_product( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat' ) {
$product = new Storefront_WooCommerce_Adjacent_Products( $in_same_term, $excluded_terms, $taxonomy, true );
return $product->get_product();
}
/**
* Retrieves the next product.
*
* @since 2.4.3
*
* @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false.
* @param array|string $excluded_terms Optional. Comma-separated list of excluded term IDs. Default empty.
* @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'product_cat'.
* @return WC_Product|false Product object if successful. False if no valid product is found.
*/
function storefront_get_next_product( $in_same_term = false, $excluded_terms = '', $taxonomy = 'product_cat' ) {
$product = new Storefront_WooCommerce_Adjacent_Products( $in_same_term, $excluded_terms, $taxonomy );
return $product->get_product();
}

View File

@@ -0,0 +1,901 @@
<?php
/**
* WooCommerce Template Functions.
*
* @package storefront
*/
if ( ! function_exists( 'storefront_before_content' ) ) {
/**
* Before Content
* Wraps all WooCommerce content in wrappers which match the theme markup
*
* @since 1.0.0
* @return void
*/
function storefront_before_content() {
?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
}
}
if ( ! function_exists( 'storefront_after_content' ) ) {
/**
* After Content
* Closes the wrapping divs
*
* @since 1.0.0
* @return void
*/
function storefront_after_content() {
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
do_action( 'storefront_sidebar' );
}
}
if ( ! function_exists( 'storefront_cart_link_fragment' ) ) {
/**
* Cart Fragments
* Ensure cart contents update when products are added to the cart via AJAX
*
* @param array $fragments Fragments to refresh via AJAX.
* @return array Fragments to refresh via AJAX
*/
function storefront_cart_link_fragment( $fragments ) {
global $woocommerce;
ob_start();
storefront_cart_link();
$fragments['a.cart-contents'] = ob_get_clean();
ob_start();
storefront_handheld_footer_bar_cart_link();
$fragments['a.footer-cart-contents'] = ob_get_clean();
return $fragments;
}
}
if ( ! function_exists( 'storefront_cart_link' ) ) {
/**
* Cart Link
* Displayed a link to the cart including the number of items present and the cart total
*
* @return void
* @since 1.0.0
*/
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
<?php /* translators: %d: number of items in cart */ ?>
<?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo wp_kses_data( sprintf( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) ); ?></span>
</a>
<?php
}
}
if ( ! function_exists( 'storefront_product_search' ) ) {
/**
* Display Product Search
*
* @since 1.0.0
* @uses storefront_is_woocommerce_activated() check if WooCommerce is activated
* @return void
*/
function storefront_product_search() {
if ( storefront_is_woocommerce_activated() ) {
?>
<div class="site-search">
<?php the_widget( 'WC_Widget_Product_Search', 'title=' ); ?>
</div>
<?php
}
}
}
if ( ! function_exists( 'storefront_header_cart' ) ) {
/**
* Display Header Cart
*
* @since 1.0.0
* @uses storefront_is_woocommerce_activated() check if WooCommerce is activated
* @return void
*/
function storefront_header_cart() {
if ( storefront_is_woocommerce_activated() ) {
if ( is_cart() ) {
$class = 'current-menu-item';
} else {
$class = '';
}
?>
<ul id="site-header-cart" class="site-header-cart menu">
<li class="<?php echo esc_attr( $class ); ?>">
<?php storefront_cart_link(); ?>
</li>
<li>
<?php the_widget( 'WC_Widget_Cart', 'title=' ); ?>
</li>
</ul>
<?php
}
}
}
if ( ! function_exists( 'storefront_upsell_display' ) ) {
/**
* Upsells
* Replace the default upsell function with our own which displays the correct number product columns
*
* @since 1.0.0
* @return void
* @uses woocommerce_upsell_display()
*/
function storefront_upsell_display() {
$columns = apply_filters( 'storefront_upsells_columns', 3 );
woocommerce_upsell_display( -1, $columns );
}
}
if ( ! function_exists( 'storefront_sorting_wrapper' ) ) {
/**
* Sorting wrapper
*
* @since 1.4.3
* @return void
*/
function storefront_sorting_wrapper() {
echo '<div class="storefront-sorting">';
}
}
if ( ! function_exists( 'storefront_sorting_wrapper_close' ) ) {
/**
* Sorting wrapper close
*
* @since 1.4.3
* @return void
*/
function storefront_sorting_wrapper_close() {
echo '</div>';
}
}
if ( ! function_exists( 'storefront_product_columns_wrapper' ) ) {
/**
* Product columns wrapper
*
* @since 2.2.0
* @return void
*/
function storefront_product_columns_wrapper() {
$columns = storefront_loop_columns();
echo '<div class="columns-' . absint( $columns ) . '">';
}
}
if ( ! function_exists( 'storefront_loop_columns' ) ) {
/**
* Default loop columns on product archives
*
* @return integer products per row
* @since 1.0.0
*/
function storefront_loop_columns() {
$columns = 3; // 3 products per row
if ( function_exists( 'wc_get_default_products_per_row' ) ) {
$columns = wc_get_default_products_per_row();
}
return apply_filters( 'storefront_loop_columns', $columns );
}
}
if ( ! function_exists( 'storefront_product_columns_wrapper_close' ) ) {
/**
* Product columns wrapper close
*
* @since 2.2.0
* @return void
*/
function storefront_product_columns_wrapper_close() {
echo '</div>';
}
}
if ( ! function_exists( 'storefront_shop_messages' ) ) {
/**
* Storefront shop messages
*
* @since 1.4.4
* @uses storefront_do_shortcode
*/
function storefront_shop_messages() {
if ( ! is_checkout() ) {
echo wp_kses_post( storefront_do_shortcode( 'woocommerce_messages' ) );
}
}
}
if ( ! function_exists( 'storefront_woocommerce_pagination' ) ) {
/**
* Storefront WooCommerce Pagination
* WooCommerce disables the product pagination inside the woocommerce_product_subcategories() function
* but since Storefront adds pagination before that function is excuted we need a separate function to
* determine whether or not to display the pagination.
*
* @since 1.4.4
*/
function storefront_woocommerce_pagination() {
if ( woocommerce_products_will_display() ) {
woocommerce_pagination();
}
}
}
if ( ! function_exists( 'storefront_product_categories' ) ) {
/**
* Display Product Categories
* Hooked into the `homepage` action in the homepage template
*
* @since 1.0.0
* @param array $args the product section args.
* @return void
*/
function storefront_product_categories( $args ) {
$args = apply_filters(
'storefront_product_categories_args', array(
'limit' => 3,
'columns' => 3,
'child_categories' => 0,
'orderby' => 'menu_order',
'title' => __( 'Shop by Category', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'product_categories', apply_filters(
'storefront_product_categories_shortcode_args', array(
'number' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'parent' => esc_attr( $args['child_categories'] ),
)
)
);
/**
* Only display the section if the shortcode returns product categories
*/
if ( false !== strpos( $shortcode_content, 'product-category' ) ) {
echo '<section class="storefront-product-section storefront-product-categories" aria-label="' . esc_attr__( 'Product Categories', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_product_categories' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_product_categories_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_product_categories' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_recent_products' ) ) {
/**
* Display Recent Products
* Hooked into the `homepage` action in the homepage template
*
* @since 1.0.0
* @param array $args the product section args.
* @return void
*/
function storefront_recent_products( $args ) {
$args = apply_filters(
'storefront_recent_products_args', array(
'limit' => 4,
'columns' => 4,
'orderby' => 'date',
'order' => 'desc',
'title' => __( 'New In', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'products', apply_filters(
'storefront_recent_products_shortcode_args', array(
'orderby' => esc_attr( $args['orderby'] ),
'order' => esc_attr( $args['order'] ),
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
)
)
);
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '<section class="storefront-product-section storefront-recent-products" aria-label="' . esc_attr__( 'Recent Products', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_recent_products' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_recent_products_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_recent_products' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_featured_products' ) ) {
/**
* Display Featured Products
* Hooked into the `homepage` action in the homepage template
*
* @since 1.0.0
* @param array $args the product section args.
* @return void
*/
function storefront_featured_products( $args ) {
$args = apply_filters(
'storefront_featured_products_args', array(
'limit' => 4,
'columns' => 4,
'orderby' => 'date',
'order' => 'desc',
'visibility' => 'featured',
'title' => __( 'We Recommend', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'products', apply_filters(
'storefront_featured_products_shortcode_args', array(
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'order' => esc_attr( $args['order'] ),
'visibility' => esc_attr( $args['visibility'] ),
)
)
);
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '<section class="storefront-product-section storefront-featured-products" aria-label="' . esc_attr__( 'Featured Products', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_featured_products' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_featured_products_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_featured_products' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_popular_products' ) ) {
/**
* Display Popular Products
* Hooked into the `homepage` action in the homepage template
*
* @since 1.0.0
* @param array $args the product section args.
* @return void
*/
function storefront_popular_products( $args ) {
$args = apply_filters(
'storefront_popular_products_args', array(
'limit' => 4,
'columns' => 4,
'orderby' => 'rating',
'order' => 'desc',
'title' => __( 'Fan Favorites', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'products', apply_filters(
'storefront_popular_products_shortcode_args', array(
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'order' => esc_attr( $args['order'] ),
)
)
);
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '<section class="storefront-product-section storefront-popular-products" aria-label="' . esc_attr__( 'Popular Products', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_popular_products' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_popular_products_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_popular_products' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_on_sale_products' ) ) {
/**
* Display On Sale Products
* Hooked into the `homepage` action in the homepage template
*
* @param array $args the product section args.
* @since 1.0.0
* @return void
*/
function storefront_on_sale_products( $args ) {
$args = apply_filters(
'storefront_on_sale_products_args', array(
'limit' => 4,
'columns' => 4,
'orderby' => 'date',
'order' => 'desc',
'on_sale' => 'true',
'title' => __( 'On Sale', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'products', apply_filters(
'storefront_on_sale_products_shortcode_args', array(
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'order' => esc_attr( $args['order'] ),
'on_sale' => esc_attr( $args['on_sale'] ),
)
)
);
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '<section class="storefront-product-section storefront-on-sale-products" aria-label="' . esc_attr__( 'On Sale Products', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_on_sale_products' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_on_sale_products_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_on_sale_products' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_best_selling_products' ) ) {
/**
* Display Best Selling Products
* Hooked into the `homepage` action in the homepage template
*
* @since 2.0.0
* @param array $args the product section args.
* @return void
*/
function storefront_best_selling_products( $args ) {
$args = apply_filters(
'storefront_best_selling_products_args', array(
'limit' => 4,
'columns' => 4,
'orderby' => 'popularity',
'order' => 'desc',
'title' => esc_attr__( 'Best Sellers', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'products', apply_filters(
'storefront_best_selling_products_shortcode_args', array(
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'order' => esc_attr( $args['order'] ),
)
)
);
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '<section class="storefront-product-section storefront-best-selling-products" aria-label="' . esc_attr__( 'Best Selling Products', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_best_selling_products' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_best_selling_products_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_best_selling_products' );
echo '</section>';
}
}
}
if ( ! function_exists( 'storefront_promoted_products' ) ) {
/**
* Featured and On-Sale Products
* Check for featured products then on-sale products and use the appropiate shortcode.
* If neither exist, it can fallback to show recently added products.
*
* @since 1.5.1
* @param integer $per_page total products to display.
* @param integer $columns columns to arrange products in to.
* @param boolean $recent_fallback Should the function display recent products as a fallback when there are no featured or on-sale products?.
* @uses storefront_is_woocommerce_activated()
* @uses wc_get_featured_product_ids()
* @uses wc_get_product_ids_on_sale()
* @uses storefront_do_shortcode()
* @return void
*/
function storefront_promoted_products( $per_page = '2', $columns = '2', $recent_fallback = true ) {
if ( storefront_is_woocommerce_activated() ) {
if ( wc_get_featured_product_ids() ) {
echo '<h2>' . esc_html__( 'Featured Products', 'storefront' ) . '</h2>';
echo storefront_do_shortcode(
'featured_products', array(
'per_page' => $per_page,
'columns' => $columns,
)
); // WPCS: XSS ok.
} elseif ( wc_get_product_ids_on_sale() ) {
echo '<h2>' . esc_html__( 'On Sale Now', 'storefront' ) . '</h2>';
echo storefront_do_shortcode(
'sale_products', array(
'per_page' => $per_page,
'columns' => $columns,
)
); // WPCS: XSS ok.
} elseif ( $recent_fallback ) {
echo '<h2>' . esc_html__( 'New In Store', 'storefront' ) . '</h2>';
echo storefront_do_shortcode(
'recent_products', array(
'per_page' => $per_page,
'columns' => $columns,
)
); // WPCS: XSS ok.
}
}
}
}
if ( ! function_exists( 'storefront_handheld_footer_bar' ) ) {
/**
* Display a menu intended for use on handheld devices
*
* @since 2.0.0
*/
function storefront_handheld_footer_bar() {
$links = array(
'my-account' => array(
'priority' => 10,
'callback' => 'storefront_handheld_footer_bar_account_link',
),
'search' => array(
'priority' => 20,
'callback' => 'storefront_handheld_footer_bar_search',
),
'cart' => array(
'priority' => 30,
'callback' => 'storefront_handheld_footer_bar_cart_link',
),
);
if ( wc_get_page_id( 'myaccount' ) === -1 ) {
unset( $links['my-account'] );
}
if ( wc_get_page_id( 'cart' ) === -1 ) {
unset( $links['cart'] );
}
$links = apply_filters( 'storefront_handheld_footer_bar_links', $links );
?>
<div class="storefront-handheld-footer-bar">
<ul class="columns-<?php echo count( $links ); ?>">
<?php foreach ( $links as $key => $link ) : ?>
<li class="<?php echo esc_attr( $key ); ?>">
<?php
if ( $link['callback'] ) {
call_user_func( $link['callback'], $key, $link );
}
?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
}
if ( ! function_exists( 'storefront_handheld_footer_bar_search' ) ) {
/**
* The search callback function for the handheld footer bar
*
* @since 2.0.0
*/
function storefront_handheld_footer_bar_search() {
echo '<a href="">' . esc_attr__( 'Search', 'storefront' ) . '</a>';
storefront_product_search();
}
}
if ( ! function_exists( 'storefront_handheld_footer_bar_cart_link' ) ) {
/**
* The cart callback function for the handheld footer bar
*
* @since 2.0.0
*/
function storefront_handheld_footer_bar_cart_link() {
?>
<a class="footer-cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
<span class="count"><?php echo wp_kses_data( WC()->cart->get_cart_contents_count() ); ?></span>
</a>
<?php
}
}
if ( ! function_exists( 'storefront_handheld_footer_bar_account_link' ) ) {
/**
* The account callback function for the handheld footer bar
*
* @since 2.0.0
*/
function storefront_handheld_footer_bar_account_link() {
echo '<a href="' . esc_url( get_permalink( get_option( 'woocommerce_myaccount_page_id' ) ) ) . '">' . esc_attr__( 'My Account', 'storefront' ) . '</a>';
}
}
if ( ! function_exists( 'storefront_single_product_pagination' ) ) {
/**
* Single Product Pagination
*
* @since 2.3.0
*/
function storefront_single_product_pagination() {
if ( class_exists( 'Storefront_Product_Pagination' ) || true !== get_theme_mod( 'storefront_product_pagination' ) ) {
return;
}
// Show only products in the same category?
$in_same_term = apply_filters( 'storefront_single_product_pagination_same_category', true );
$excluded_terms = apply_filters( 'storefront_single_product_pagination_excluded_terms', '' );
$taxonomy = apply_filters( 'storefront_single_product_pagination_taxonomy', 'product_cat' );
$previous_product = storefront_get_previous_product( $in_same_term, $excluded_terms, $taxonomy );
$next_product = storefront_get_next_product( $in_same_term, $excluded_terms, $taxonomy );
if ( ! $previous_product && ! $next_product ) {
return;
}
?>
<nav class="storefront-product-pagination" aria-label="<?php esc_attr_e( 'More products', 'storefront' ); ?>">
<?php if ( $previous_product ) : ?>
<a href="<?php echo esc_url( $previous_product->get_permalink() ); ?>" rel="prev">
<?php echo wp_kses_post( $previous_product->get_image() ); ?>
<span class="storefront-product-pagination__title"><?php echo wp_kses_post( $previous_product->get_name() ); ?></span>
</a>
<?php endif; ?>
<?php if ( $next_product ) : ?>
<a href="<?php echo esc_url( $next_product->get_permalink() ); ?>" rel="next">
<?php echo wp_kses_post( $next_product->get_image() ); ?>
<span class="storefront-product-pagination__title"><?php echo wp_kses_post( $next_product->get_name() ); ?></span>
</a>
<?php endif; ?>
</nav><!-- .storefront-product-pagination -->
<?php
}
}
if ( ! function_exists( 'storefront_sticky_single_add_to_cart' ) ) {
/**
* Sticky Add to Cart
*
* @since 2.3.0
*/
function storefront_sticky_single_add_to_cart() {
global $product;
if ( class_exists( 'Storefront_Sticky_Add_to_Cart' ) || true !== get_theme_mod( 'storefront_sticky_add_to_cart' ) ) {
return;
}
if ( ! is_product() ) {
return;
}
$show = false;
if ( $product->is_purchasable() && $product->is_in_stock() ) {
$show = true;
} else if ( $product->is_type( 'external' ) ) {
$show = true;
}
if ( ! $show ) {
return;
}
$params = apply_filters(
'storefront_sticky_add_to_cart_params', array(
'trigger_class' => 'entry-summary',
)
);
wp_localize_script( 'storefront-sticky-add-to-cart', 'storefront_sticky_add_to_cart_params', $params );
wp_enqueue_script( 'storefront-sticky-add-to-cart' );
?>
<section class="storefront-sticky-add-to-cart">
<div class="col-full">
<div class="storefront-sticky-add-to-cart__content">
<?php echo wp_kses_post( woocommerce_get_product_thumbnail() ); ?>
<div class="storefront-sticky-add-to-cart__content-product-info">
<span class="storefront-sticky-add-to-cart__content-title"><?php esc_attr_e( 'You\'re viewing:', 'storefront' ); ?> <strong><?php the_title(); ?></strong></span>
<span class="storefront-sticky-add-to-cart__content-price"><?php echo wp_kses_post( $product->get_price_html() ); ?></span>
<?php echo wp_kses_post( wc_get_rating_html( $product->get_average_rating() ) ); ?>
</div>
<a href="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="storefront-sticky-add-to-cart__content-button button alt">
<?php echo esc_attr( $product->add_to_cart_text() ); ?>
</a>
</div>
</div>
</section><!-- .storefront-sticky-add-to-cart -->
<?php
}
}
if ( ! function_exists( 'storefront_woocommerce_brands_homepage_section' ) ) {
/**
* Display WooCommerce Brands
* Hooked into the `homepage` action in the homepage template.
* Requires WooCommerce Brands.
*
* @since 2.3.0
* @link https://woocommerce.com/products/brands/
* @uses apply_filters()
* @uses storefront_do_shortcode()
* @uses wp_kses_post()
* @uses do_action()
* @return void
*/
function storefront_woocommerce_brands_homepage_section() {
$args = apply_filters(
'storefront_woocommerce_brands_args', array(
'number' => 6,
'columns' => 4,
'orderby' => 'name',
'show_empty' => false,
'title' => __( 'Shop by Brand', 'storefront' ),
)
);
$shortcode_content = storefront_do_shortcode(
'product_brand_thumbnails', apply_filters(
'storefront_woocommerce_brands_shortcode_args', array(
'number' => absint( $args['number'] ),
'columns' => absint( $args['columns'] ),
'orderby' => esc_attr( $args['orderby'] ),
'show_empty' => (bool) $args['show_empty'],
)
)
);
echo '<section class="storefront-product-section storefront-woocommerce-brands" aria-label="' . esc_attr__( 'Product Brands', 'storefront' ) . '">';
do_action( 'storefront_homepage_before_woocommerce_brands' );
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
do_action( 'storefront_homepage_after_woocommerce_brands_title' );
echo $shortcode_content; // WPCS: XSS ok.
do_action( 'storefront_homepage_after_woocommerce_brands' );
echo '</section>';
}
}
if ( ! function_exists( 'storefront_woocommerce_brands_archive' ) ) {
/**
* Display brand image on brand archives
* Requires WooCommerce Brands.
*
* @since 2.3.0
* @link https://woocommerce.com/products/brands/
* @uses is_tax()
* @uses wp_kses_post()
* @uses get_brand_thumbnail_image()
* @uses get_queried_object()
* @return void
*/
function storefront_woocommerce_brands_archive() {
if ( is_tax( 'product_brand' ) ) {
echo wp_kses_post( get_brand_thumbnail_image( get_queried_object() ) );
}
}
}
if ( ! function_exists( 'storefront_woocommerce_brands_single' ) ) {
/**
* Output product brand image for use on single product pages
* Requires WooCommerce Brands.
*
* @since 2.3.0
* @link https://woocommerce.com/products/brands/
* @uses storefront_do_shortcode()
* @uses wp_kses_post()
* @return void
*/
function storefront_woocommerce_brands_single() {
$brand = storefront_do_shortcode(
'product_brand', array(
'class' => '',
)
);
if ( empty( $brand ) ) {
return;
}
?>
<div class="storefront-wc-brands-single-product">
<?php echo wp_kses_post( $brand ); ?>
</div>
<?php
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Storefront WooCommerce hooks
*
* @package storefront
*/
/**
* Homepage
*
* @see storefront_product_categories()
* @see storefront_recent_products()
* @see storefront_featured_products()
* @see storefront_popular_products()
* @see storefront_on_sale_products()
* @see storefront_best_selling_products()
*/
add_action( 'homepage', 'storefront_product_categories', 20 );
add_action( 'homepage', 'storefront_recent_products', 30 );
add_action( 'homepage', 'storefront_featured_products', 40 );
add_action( 'homepage', 'storefront_popular_products', 50 );
add_action( 'homepage', 'storefront_on_sale_products', 60 );
add_action( 'homepage', 'storefront_best_selling_products', 70 );
/**
* Layout
*
* @see storefront_before_content()
* @see storefront_after_content()
* @see woocommerce_breadcrumb()
* @see storefront_shop_messages()
*/
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
add_action( 'woocommerce_before_main_content', 'storefront_before_content', 10 );
add_action( 'woocommerce_after_main_content', 'storefront_after_content', 10 );
add_action( 'storefront_content_top', 'storefront_shop_messages', 15 );
add_action( 'storefront_before_content', 'woocommerce_breadcrumb', 10 );
add_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper', 9 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 30 );
add_action( 'woocommerce_after_shop_loop', 'storefront_sorting_wrapper_close', 31 );
add_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper', 9 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );
add_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
add_action( 'woocommerce_before_shop_loop', 'storefront_woocommerce_pagination', 30 );
add_action( 'woocommerce_before_shop_loop', 'storefront_sorting_wrapper_close', 31 );
add_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
// Legacy WooCommerce columns filter.
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '3.3', '<' ) ) {
add_filter( 'loop_shop_columns', 'storefront_loop_columns' );
add_action( 'woocommerce_before_shop_loop', 'storefront_product_columns_wrapper', 40 );
add_action( 'woocommerce_after_shop_loop', 'storefront_product_columns_wrapper_close', 40 );
}
/**
* Products
*
* @see storefront_edit_post_link()
* @see storefront_upsell_display()
* @see storefront_single_product_pagination()
* @see storefront_sticky_single_add_to_cart()
*/
add_action( 'woocommerce_single_product_summary', 'storefront_edit_post_link', 60 );
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15 );
add_action( 'woocommerce_after_single_product_summary', 'storefront_upsell_display', 15 );
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
add_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 6 );
add_action( 'woocommerce_after_single_product_summary', 'storefront_single_product_pagination', 30 );
add_action( 'storefront_after_footer', 'storefront_sticky_single_add_to_cart', 999 );
/**
* Header
*
* @see storefront_product_search()
* @see storefront_header_cart()
*/
add_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_header_cart', 60 );
/**
* Cart fragment
*
* @see storefront_cart_link_fragment()
*/
if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '2.3', '>=' ) ) {
add_filter( 'woocommerce_add_to_cart_fragments', 'storefront_cart_link_fragment' );
} else {
add_filter( 'add_to_cart_fragments', 'storefront_cart_link_fragment' );
}
/**
* Integrations
*
* @see storefront_woocommerce_brands_archive()
* @see storefront_woocommerce_brands_single()
* @see storefront_woocommerce_brands_homepage_section()
*/
if ( class_exists( 'WC_Brands' ) ) {
add_action( 'woocommerce_archive_description', 'storefront_woocommerce_brands_archive', 5 );
add_action( 'woocommerce_single_product_summary', 'storefront_woocommerce_brands_single', 4 );
add_action( 'homepage', 'storefront_woocommerce_brands_homepage_section', 80 );
}