* @copyright Copyright (c) 2018, Chris Baldelomar * @link https://webplantmedia.com/product/brimstone-wordpress-theme/ * @license http://www.gnu.org/licenses/gpl-2.0.html */ if ( ! defined( 'ABSPATH' ) ) { exit; } if ( ! class_exists( 'Brimstone_WooCommerce' ) ) : /** * Class: WooCommerce Integration class. * * @since Brimstone 1.01 */ class Brimstone_WooCommerce { /** * __construct * * @since Brimstone 1.01 * * @return void */ public function __construct() { add_filter( 'woocommerce_product_get_image', array( $this, 'woocommerce_product_get_image' ) ); add_action( 'wp', array( $this, 'disable_jetpack_infinite_scroll' ) ); add_filter( 'woocommerce_pagination_args', array( $this, 'woocommerce_pagination_args' ) ); add_filter( 'woocommerce_comment_pagination_args', array( $this, 'woocommerce_pagination_args' ) ); add_filter( 'loop_shop_per_page', array( $this, 'loop_shop_per_page' ), 20 ); add_filter( 'loop_shop_columns', array( $this, 'loop_columns' ) ); add_filter( 'woocommerce_show_page_title', array( $this, 'hide_title' ) ); add_filter( 'get_the_archive_title', array( $this, 'get_the_archive_title' ), 10, 1 ); add_action( 'after_setup_theme', array( $this, 'woocommerce_setup' ) ); add_action( 'wp_loaded', array( $this, 'check_features' ), 11 ); add_action( 'wp', array( $this, 'check_image_size' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'woocommerce_enqueue' ) ); add_filter( 'woocommerce_output_related_products_args', array( $this, 'related_products_args' ) ); add_filter( 'woocommerce_upsell_display_args', array( $this, 'related_products_args' ) ); remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 ); remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 ); add_action( 'woocommerce_before_main_content', array( $this, 'output_content_wrapper' ), 10 ); add_action( 'woocommerce_after_main_content', array( $this, 'output_content_wrapper_end' ), 10 ); add_action( 'brimstone_cart', array( $this, 'woocommerce_cart_dropdown' ), 10 ); add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'woocommerce_header_cart_fragments' ) ); add_action( 'woocommerce_before_mini_cart', array( $this, 'add_header_mini_cart' ), 10 ); // Add header for payment info. add_action( 'woocommerce_review_order_before_payment', array( $this, 'before_shipping_title' ), 10 ); add_filter( 'woocommerce_short_description', 'brimstone_the_content', 11 ); } /** * Shop image backdrop * * @since Brimstone 1.01 * * @param string $image * @return string */ public function woocommerce_product_get_image( $image ) { global $brimstone; if ( $brimstone['shop_image_backdrop'] ) { return '' . $image . ''; } return $image; } /** * No need for infinit scroll on WooCommerce pages. * * @since Brimstone 1.01 * * @return void */ public function disable_jetpack_infinite_scroll() { if ( is_woocommerce() ) { remove_theme_support( 'infinite-scroll' ); } } /** * Add font icons to pagination * * @since Brimstone 1.01 * * @param array $args * @return array */ public function woocommerce_pagination_args( $args ) { $args['prev_text'] = ''; $args['next_text'] = ''; return $args; } /** * Change products per page * * @since Brimstone 1.01 * * @param int $cols * @return int */ public function loop_shop_per_page( $cols ) { global $brimstone; return $brimstone['shop_products_per_page']; } /** * Add theme support * * @since Brimstone 1.01 * * @return void */ public function woocommerce_setup() { // Declare WooCommerce support. add_theme_support( 'woocommerce', array( // 'gallery_thumbnail_image_width' => 100, ) ); add_theme_support( 'wc-product-gallery-zoom' ); add_theme_support( 'wc-product-gallery-lightbox' ); add_theme_support( 'wc-product-gallery-slider' ); } /** * Check features with user selected options from Customizer * * @since Brimstone 1.01 * * @return void */ public function check_features() { global $brimstone; if ( $brimstone['shop_disable_gallery_zoom'] ) { remove_theme_support( 'wc-product-gallery-zoom' ); } if ( $brimstone['shop_disable_gallery_lightbox'] ) { remove_theme_support( 'wc-product-gallery-lightbox' ); } if ( $brimstone['shop_disable_gallery_slider'] ) { remove_theme_support( 'wc-product-gallery-slider' ); } if ( $brimstone['shop_hide_stars'] ) { remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 ); } if ( $brimstone['shop_product_hide_stars'] ) { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 ); } if ( $brimstone['shop_hide_breadcrumbs'] ) { remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 ); } if ( $brimstone['shop_hide_result_count'] ) { remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); } if ( $brimstone['shop_hide_catalog_ordering'] ) { remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); } if ( $brimstone['shop_product_hide_meta'] ) { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 ); } } /** * Change image size depending on columns * * @since Brimstone 1.01 * * @return void */ public function check_image_size() { global $brimstone; add_filter( 'single_product_archive_thumbnail_size', array( $this, 'single_product_archive_thumbnail_size' ), 10, 1 ); add_filter( 'subcategory_archive_thumbnail_size', array( $this, 'single_product_archive_thumbnail_size' ), 10, 1 ); } /** * Change product image size * * @since Brimstone 1.01 * * @return string */ public function single_product_archive_thumbnail_size( $size ) { global $brimstone; if ( is_product_taxonomy() ) { return $brimstone['shop_archive_image_size']; } elseif ( is_shop() ) { return $brimstone['shop_image_size']; } elseif ( is_product() ) { return $brimstone['shop_related_products_image_size']; } return $size; } /** * Set columns depending on type of page. * * @since Brimstone 1.01 * * @param int $number_columns * @return int */ public function loop_columns( $number_columns ) { global $brimstone; if ( is_product_category() || is_product_taxonomy() ) { return $brimstone['shop_archive_columns']; } return $brimstone['shop_columns']; } /** * Hide Title * * @since Brimstone 1.01 * * @param mixed $title * @return bool */ public function hide_title( $title ) { return false; } /** * Adjust shop title * * @since Brimstone 1.01 * * @param string $title * @return string */ public function get_the_archive_title( $title ) { if ( is_shop() ) { $title = woocommerce_page_title( false ); } elseif ( is_product_taxonomy() ) { $pieces = explode( ': ', $title ); if ( 2 === count( $pieces ) ) { $shop_page_id = wc_get_page_id( 'shop' ); $page_title = get_the_title( $shop_page_id ); $page_title = apply_filters( 'woocommerce_page_title', $page_title ); $pieces[0] = $page_title; $title = implode( ': ', $pieces ); return $title; } } return $title; } /** * Enqueue scripts and styles * * @since Brimstone 1.01 * * @return void */ public function woocommerce_enqueue() { wp_enqueue_style( 'brimstone-woocommerce', get_template_directory_uri() . '/css/woocommerce.css', array( 'brimstone-style' ), BRIMSTONE_VERSION ); wp_enqueue_script( 'brimstone-woocommerce', get_template_directory_uri() . '/js/woocommerce.js', array(), BRIMSTONE_VERSION, true ); } /** * Set related products args * * @since Brimstone 1.01 * * @param array $args * @return array */ public function related_products_args( $args ) { global $brimstone; $args = array_merge( $args, apply_filters( 'brimstone_related_products_args', array( 'posts_per_page' => $brimstone['shop_related_products_columns'], 'columns' => $brimstone['shop_related_products_columns'], ) ) ); return $args; } /** * Set before content wrapper * * @since Brimstone 1.01 * * @return void */ public function output_content_wrapper() { global $brimstone; echo '