Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,310 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Inline;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Helpers
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Inline
*/
class Helpers {
/**
* Fetch the sale/regular price for this product, format it and prepare it to be rendered
*
* @param string $price_type - sale / regular
* @param \WC_Product $product
* @param array $attr
*
* @return string
*/
public static function render_price( $price_type, $product, $attr ) {
$add_currency = ! empty( $attr[ Main::PRICE_INCLUDE_CURRENCY_SYMBOL ] );
$show_decimals = ! empty( $attr[ Main::PRICE_SHOW_DECIMALS ] );
if ( $product instanceof \WC_Product_Variable ) {
$prices = $product->get_variation_prices();
if ( empty( $prices["{$price_type}_price"] ) ) {
$price = '';
} else {
$min_price = min( $prices["{$price_type}_price"] );
$max_price = max( $prices["{$price_type}_price"] );
if ( $min_price === $max_price ) {
$price = static::prepare_price( $min_price, $add_currency, $show_decimals );
} else {
$price = static::prepare_price( $min_price, $add_currency, $show_decimals ) . ' ' .
static::prepare_price( $max_price, $add_currency, $show_decimals );
}
}
} else {
$price = call_user_func( [ $product, "get_{$price_type}_price" ] );
$price = static::prepare_price( $price, $add_currency, $show_decimals );
}
return $price;
}
/**
* Prepare price for display - add currency and maybe show decimals
*
* @param $price
* @param $add_currency
* @param $show_decimals
*
* @return string
*/
private static function prepare_price( $price, $add_currency = true, $show_decimals = true ) {
$price = (float) $price;
$price = static::get_formatted_price( $price, $show_decimals );
if ( $add_currency ) {
$price = static::add_currency_symbol( $price );
}
return $price;
}
/**
* Format the current price, respecting WooCommerce settings: add thousand separators, keep or remove decimals, etc
* The idea is to display the shortcodes just like WooCommerce displays the regular prices
*
* @param float $price
* @param bool $show_decimals
*
* @return string
*/
public static function get_formatted_price( $price, $show_decimals = true ) {
$decimals = $show_decimals ? wc_get_price_decimals() : 0;
return number_format( $price, $decimals, wc_get_price_decimal_separator(), wc_get_price_thousand_separator() );
}
/**
* Add the currency symbol to the price while respecting the position from the WooCommerce settings.
*
* @param $price
*
* @return string
*/
private static function add_currency_symbol( $price ) {
$prefix = '';
$suffix = '';
$symbol = static::get_currency_symbol();
switch ( get_option( 'woocommerce_currency_pos' ) ) {
case 'left_space':
$prefix = $symbol . ' ';
break;
case 'left':
$prefix = $symbol;
break;
case 'right_space':
$suffix = ' ' . $symbol;
break;
case 'right':
$suffix = $symbol;
break;
default:
break;
}
return $prefix . $price . $suffix;
}
/**
* Wrapper for the WooCommerce currency symbol getter.
*
* @return string
*/
public static function get_currency_symbol() {
return get_woocommerce_currency_symbol();
}
/**
* Currently available inline shortcodes
*
* @return array
*/
public static function available_shortcodes() {
return array(
'product_description' => array(
'name' => __( 'Product short description', 'thrive-cb' ),
'controls' => [],
'type' => '',
),
'product_category' => array(
'name' => __( 'Product category', 'thrive-cb' ),
'controls' => [],
'type' => '',
),
'product_tags' => array(
'name' => __( 'Product tags', 'thrive-cb' ),
'controls' => [],
'type' => '',
),
'_sale_price' => array(
'name' => __( 'Product sale price', 'thrive-cb' ),
'controls' => static::get_control_config( [
Main::PRICE_INCLUDE_CURRENCY_SYMBOL,
Main::PRICE_SHOW_DECIMALS,
] ),
'type' => 'price',
),
'_regular_price' => array(
'name' => __( 'Product regular price', 'thrive-cb' ),
'controls' => static::get_control_config( [
Main::PRICE_ON_SALE_EFFECT,
Main::PRICE_INCLUDE_CURRENCY_SYMBOL,
Main::PRICE_SHOW_DECIMALS,
] ),
'type' => 'price',
),
'_wc_average_rating' => array(
'name' => __( 'Product average rating', 'thrive-cb' ),
'controls' => [],
'type' => '',
),
);
}
/**
* Return the full shortcode config for the given shortcode keys.
*
* @param array $shortcode_keys
*
* @return array
*/
public static function get_control_config( $shortcode_keys ) {
$config = [];
foreach ( $shortcode_keys as $shortcode_key ) {
switch ( $shortcode_key ) {
case Main::PRICE_ON_SALE_EFFECT:
$config[ $shortcode_key ] = array(
'type' => 'select',
'label' => __( 'If product is on sale', 'thrive-cb' ),
'value' => array(
/* the first option is the default one */
'strikethrough' => __( 'Strikethrough (e.g. ̶3̶0̶.̶0̶0̶)', 'thrive-cb' ),
'fade_n_strike' => __( 'Fade and strikethrough', 'thrive-cb' ),
'fade' => __( 'Fade', 'thrive-cb' ),
'normal' => __( 'Display as normal', 'thrive-cb' ),
),
);
break;
case Main::PRICE_INCLUDE_CURRENCY_SYMBOL:
$config[ $shortcode_key ] = array(
'type' => 'checkbox',
'label' => __( 'Include currency symbol', 'thrive-cb' ),
'value' => true, /* must be checked by default */
'disable_br' => true,
);
break;
case Main::PRICE_SHOW_DECIMALS:
$config[ $shortcode_key ] = array(
'type' => 'checkbox',
'label' => __( 'Show minor units (cents, pence etc.)', 'thrive-cb' ),
'value' => true, /* must be checked by default */
'disable_br' => true,
);
break;
default:
break;
}
}
return $config;
}
/**
* Remove the decimals from the price and return it ( but keep the thousand separators )
*
* @param $price
*
* @return mixed
*/
public static function get_price_without_decimals( $price ) {
/* remove the thousand separator 1,345,543.56 --> 1345543.56 */
$price = str_replace( wc_get_price_thousand_separator(), '', $price );
/* cast to (int) in order to remove the decimals 1345543.56 --> 1345543 */
$base_price = (int) $price;
/* add the thousand separator back 1345543 --> 1,345,543 */
$price = static::get_formatted_price( $base_price, false );
return $price;
}
/**
* Dynamic links available in the editor
*
* @return array
*/
public static function get_dynamic_links() {
return array(
'WooCommerce' => array(
'links' => array(
array(
array(
'name' => __( 'Add to cart product', 'thrive-cb' ),
'label' => __( 'Add to cart product', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'dynamic_product_link',
),
array(
'name' => __( 'Cart page', 'thrive-cb' ),
'label' => __( 'Cart page', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'cart_url',
),
array(
'name' => __( 'Shop page', 'thrive-cb' ),
'label' => __( 'Shop page', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'shop_url',
),
array(
'name' => __( 'Checkout page', 'thrive-cb' ),
'label' => __( 'Checkout page', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'checkout_url',
),
array(
'name' => __( 'My account', 'thrive-cb' ),
'label' => __( 'My account', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'my_account_url',
),
array(
'name' => __( 'Add to cart', 'thrive-cb' ),
'label' => __( 'Add to cart', 'thrive-cb' ),
'url' => '',
'show' => true,
'id' => 'add_to_cart',
),
),
),
'shortcode' => Main::LINK_SHORTCODE,
),
);
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Inline;
use TCB\Integrations\WooCommerce\Main as Woo_Main;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Hooks
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Inline
*/
class Hooks {
public static function add() {
add_filter( 'tcb_inline_shortcodes', [ __CLASS__, 'tcb_inline_shortcodes' ], 100 );
add_filter( 'tcb_post_list_post_info', [ __CLASS__, 'shortcode_real_data' ], 10, 2 );
add_filter( 'tcb_content_allowed_shortcodes', [ __CLASS__, 'content_allowed_shortcodes_filter' ] );
add_filter( 'tcb_dynamiclink_data', [ __CLASS__, 'dynamiclink_data_filter' ] );
}
/**
* Add WooCommerce inline shortcodes
*
* @param $shortcodes
*
* @return array
*/
public static function tcb_inline_shortcodes( $shortcodes ) {
foreach ( Helpers::available_shortcodes() as $shortcode_id => $config ) {
/* each shortcode config has a hidden ID field */
$shortcode_id_config = [
'id' => [
'extra_options' => [],
'real_data' => $config['name'],
'type' => 'hidden',
'value' => $shortcode_id,
],
];
$shortcodes['Post'][] = array(
'name' => $config['name'],
'option' => $config['name'],
'value' => Main::META_SHORTCODE,
'extra_param' => $shortcode_id,
'input' => array_merge( $shortcode_id_config, $config['controls'] ), /* some shortcodes have extra controls */
);
}
return $shortcodes;
}
/**
* Add extra info for products needed for inline shortcodes
*
* @param $post_info
* @param $post_id
*
* @return mixed
*/
public static function shortcode_real_data( $post_info, $post_id ) {
if ( get_post_type( $post_id ) === Woo_Main::POST_TYPE ) {
foreach ( Helpers::available_shortcodes() as $shortcode_id => $config ) {
$attr = [];
/* if the shortcode is a 'price' shortcode, make sure we get the full price ( including decimals ) at the start */
if ( $config['type'] === 'price' ) {
$attr[ Main::PRICE_SHOW_DECIMALS ] = 1;
}
$shortcode_value = Main::do_shortcode( $shortcode_id, $attr );
$shortcode_data = [
'value' => $shortcode_value,
];
if ( $config['type'] === 'price' ) {
$shortcode_data['price_without_decimals'] = Helpers::get_price_without_decimals( $shortcode_value );
}
$post_info[ Main::META_SHORTCODE ][ $shortcode_id ] = $shortcode_data;
}
}
return $post_info;
}
/**
* When editing a landing page, allow woo shortcodes to render
*
* @param $shortcodes
*
* @return array
*/
public static function content_allowed_shortcodes_filter( $shortcodes ) {
if ( tve_post_is_landing_page() && is_editor_page() ) {
$shortcodes[] = Main::META_SHORTCODE;
$shortcodes[] = Main::LINK_SHORTCODE;
}
return $shortcodes;
}
/**
* Add dynamic WooCommerce links
*
* @param $dynamic_links
*
* @return array
*/
public static function dynamiclink_data_filter( $dynamic_links ) {
return array_merge_recursive( $dynamic_links, Helpers::get_dynamic_links() );
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Inline;
use TCB\Integrations\WooCommerce\Main as Woo_Main;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Main
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Inline
*/
class Main {
const META_SHORTCODE = 'thrive_woo_meta_shortcode';
const LINK_SHORTCODE = 'thrive_woo_link_shortcode';
/* price shortcode attributes */
const PRICE_ON_SALE_EFFECT = 'on_sale_effect';
const PRICE_INCLUDE_CURRENCY_SYMBOL = 'include_currency_symbol';
const PRICE_SHOW_DECIMALS = 'show_decimals';
const PATH = 'classes/shortcodes/inline/';
/**
*
*/
public static function init() {
$shortcode_path = Woo_Main::get_integration_path( static::PATH );
require_once $shortcode_path . 'class-helpers.php';
require_once $shortcode_path . 'class-hooks.php';
Hooks::add();
add_shortcode( static::META_SHORTCODE, [ __CLASS__, 'render_meta_shortcode' ] );
add_shortcode( static::LINK_SHORTCODE, [ __CLASS__, 'render_link_shortcode' ] );
}
/**
* Render inline shortcodes - stored into the meta of the current product
*
* @param $attr
*
* @return mixed|string
*/
public static function render_meta_shortcode( $attr ) {
if ( empty( $attr['id'] ) ) {
$content = '';
} else {
$content = static::do_shortcode( $attr['id'], $attr );
}
return $content;
}
/**
* Render our WooCommerce shortcodes
*
* @param string $shortcode_id
* @param array $attr
*
* @return mixed|string
*/
public static function do_shortcode( $shortcode_id, $attr = [] ) {
$content = '';
if ( array_key_exists( $shortcode_id, Helpers::available_shortcodes() ) ) {
/* always fetch the product based on the ID, otherwise the post list custom loop can mess this up */
$product_id = get_the_ID();
$product = wc_get_product( $product_id );
if ( ! $product ) {
return '';
}
switch ( $shortcode_id ) {
case '_sale_price':
$content = Helpers::render_price( 'sale', $product, $attr );
break;
case '_regular_price':
$content = Helpers::render_price( 'regular', $product, $attr );
break;
case '_wc_average_rating':
$content = $product->get_average_rating();
break;
case 'product_description':
$content = $product->get_short_description();
break;
case 'product_category':
$content = get_the_term_list( $product_id, 'product_cat', null, ', ', null );
break;
case 'product_tags':
$content = get_the_term_list( $product_id, 'product_tag', null, ', ', null );
break;
default:
$content = '';
}
}
return $content;
}
/**
* Render shortcodes for dynamic links
*
* @param $attr
*
* @return mixed|string
*/
public static function render_link_shortcode( $attr ) {
$attr = shortcode_atts( [
'id' => '',
'product-id' => '',
'product-variation-id' => '',
'redirect-destination' => '',
], $attr );
switch ( $attr['id'] ) {
case 'cart_url':
$link = wc_get_cart_url();
break;
case 'shop_url':
$link = Woo_Main::get_shop_url();
break;
case 'checkout_url':
$link = Woo_Main::get_checkout_url();
break;
case 'my_account_url':
$link = wc_get_page_permalink( 'myaccount' );
break;
case 'add_to_cart':
$link = wc_get_cart_url() . '?add-to-cart=' . get_the_ID();
break;
case 'dynamic_product_link':
$product_id = $attr['product-id'];
$link = $attr['redirect-destination'] === 'cart' ? wc_get_cart_url() : Woo_Main::get_checkout_url();
if ( $product_id ) {
$variation_id = empty( $attr['product-variation-id'] ) ? 0 : $attr['product-variation-id'];
$product = wc_get_product( $product_id );
$link = add_query_arg( [
'add-to-cart' => $variation_id ? $variation_id : $product_id,
], $link );
if ( $product && $product->get_type() === 'grouped' ) {
$children = $product->get_children();
foreach ( $children as $child ) {
//the default quantity for each part of a grouped product is 1
$link .= "&quantity[$child]=1";
}
}
}
break;
default:
$link = '#';
}
return $link;
}
/**
* @return array
*/
public static function get_localized_data() {
return array(
'currency_symbol' => Helpers::get_currency_symbol(),
'currency_position' => get_option( 'woocommerce_currency_pos' ),
'meta_shortcode' => static::META_SHORTCODE,
);
}
}

View File

@@ -0,0 +1,70 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Abstract_Sub_Element
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Abstract_Sub_Element extends \TCB_Element_Abstract {
/**
* All sub elements are not visible
*
* @return bool
*/
public function hide() {
return true;
}
public function has_important_border() {
return false;
}
/**
* TODO find a better way to define custom settings
*
* @param bool $hide_typography
* @param bool $important_border
*
* @return array
*/
public function _components( $hide_typography = false, $important_border = false ) {
$components = $this->general_components();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['animation'] = [ 'hidden' => true ];
$components['responsive'] = [ 'hidden' => true ];
$components['styles-templates'] = [ 'hidden' => true ];
if ( $hide_typography ) {
$components['typography'] = [ 'hidden' => true ];
} else {
foreach ( $components['typography']['config'] as $control => $config ) {
if ( in_array( $control, [ 'css_suffix', 'css_prefix' ] ) ) {
continue;
}
/* typography should apply only on the current element */
$components['typography']['config'][ $control ]['css_suffix'] = [ '' ];
}
}
if ( $this->has_important_border() ) {
$components['borders']['config']['Borders']['important'] = true;
}
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
return $components;
}
}

View File

@@ -0,0 +1,216 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Element
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Element extends \TCB_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Mini Cart', 'thrive-cb' );
}
/**
* @return string
*/
public function icon() {
return 'mini-cart';
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart';
}
/**
* @return array
*/
public function own_components() {
$components = array(
'mini-cart' => array(
'config' => array(
'color' => array(
'config' => array(
'default' => '000',
'label' => __( 'Color', 'thrive-cb' ),
),
'extends' => 'ColorPicker',
),
'align' => array(
'config' => array(
'name' => __( 'Alignment', 'thrive-cb' ),
'buttons' => array(
array(
'icon' => 'a_left',
'text' => '',
'value' => 'left',
'default' => true,
),
array(
'icon' => 'a_center',
'text' => '',
'value' => 'center',
),
array(
'icon' => 'a_right',
'text' => '',
'value' => 'right',
),
),
),
'extends' => 'ButtonGroup',
),
'size' => array(
'config' => array(
'min' => '10',
'max' => '100',
'um' => [ 'px' ],
'label' => __( 'Size', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'cart-type' => array(
'config' => array(
'buttons' => array(
array(
'value' => 'icon',
'text' => __( 'Icon', 'thrive-cb' ),
'default' => true,
),
array(
'value' => 'amount',
'text' => __( 'Amount', 'thrive-cb' ),
),
array(
'value' => 'text',
'text' => __( 'Text', 'thrive-cb' ),
),
),
),
'extends' => 'ButtonGroup',
),
'cart-text' => array(
'config' => array(
'label' => __( 'Text', 'thrive-cb' ),
'extra_attrs' => '',
'placeholder' => 'e.g. Cart',
'default' => 'Cart',
),
'extends' => 'LabelInput',
),
'icon-position' => array(
'config' => array(
'name' => __( 'Icon Position', 'thrive-cb' ),
'buttons' => array(
array(
'icon' => '',
'text' => 'Left',
'value' => 'left',
'default' => true,
),
array(
'icon' => '',
'text' => 'Right',
'value' => 'right',
),
),
'default' => 'left',
),
'extends' => 'ButtonGroup',
),
'trigger' => array(
'config' => array(
'name' => __( 'Show items on', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'Click', 'thrive-cb' ),
'value' => 'click',
),
array(
'name' => __( 'Hover', 'thrive-cb' ),
'value' => 'hover',
),
),
'default' => 'click',
),
'extends' => 'Select',
),
'direction' => array(
'config' => array(
'name' => __( 'Position', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'Underneath', 'thrive-cb' ),
'value' => 'under',
),
array(
'name' => __( 'From the right', 'thrive-cb' ),
'value' => 'right',
),
array(
'name' => __( 'From the left', 'thrive-cb' ),
'value' => 'left',
),
),
'default' => 'under',
),
'extends' => 'Select',
),
),
),
'styles-templates' => [ 'hidden' => true ],
'layout' => [ 'disabled_controls' => [ 'Alignment', 'Display', 'Overflow', 'ScrollStyle' ] ],
'animation' => [ 'disabled_controls' => [ '.anim-popup', '.anim-link' ] ],
);
$general_components = $this->general_components();
$components['typography'] = $general_components['typography'];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( in_array( $control, [ 'css_suffix', 'css_prefix' ] ) ) {
continue;
}
$components['typography']['config'][ $control ]['css_suffix'] = [ ' .tcb-woo-mini-cart-amount', ' .tcb-woo-mini-cart-text' ];
}
return $components;
}
/**
* Element category that will be displayed in the sidebar
*
* @return string
*/
public function category() {
return 'WooCommerce';
}
/**
* Whether or not this element can be edited while under :hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
}
return new Element( 'mini-cart' );

View File

@@ -0,0 +1,63 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Hooks
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Hooks {
public static function add() {
add_filter( 'tcb_content_allowed_shortcodes', [ __CLASS__, 'content_allowed_shortcodes_filter' ] );
add_filter( 'tcb_element_instances', [ __CLASS__, 'tcb_element_instances' ] );
}
/**
* Allow the shop shortcode to be rendered in the editor
*
* @param $shortcodes
*
* @return array
*/
public static function content_allowed_shortcodes_filter( $shortcodes ) {
if ( is_editor_page() ) {
$shortcodes[] = Main::SHORTCODE;
}
return $shortcodes;
}
/**
* @param $instances
*
* @return mixed
*/
public static function tcb_element_instances( $instances ) {
$mini_cart_element = require_once __DIR__ . '/class-element.php';
$instances[ $mini_cart_element->tag() ] = $mini_cart_element;
require_once __DIR__ . '/class-abstract-sub-element.php';
$files = array_diff( scandir( __DIR__ . '/sub-elements' ), [ '.', '..' ] );
foreach ( $files as $file ) {
$instance = require_once __DIR__ . '/sub-elements/' . $file;
$instances[ $instance->tag() ] = $instance;
}
return $instances;
}
}

View File

@@ -0,0 +1,221 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
use TCB\Integrations\WooCommerce\Main as Main_Woo;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Main
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Main {
const SHORTCODE = 'tcb_woo_mini_cart';
public static function init() {
add_shortcode( static::SHORTCODE, [ __CLASS__, 'render' ] );
require_once __DIR__ . '/class-hooks.php';
Hooks::add();
}
/**
* Render mini cart
*
* @param array $attr
* @param string $content
*
* @return string
*/
public static function render( $attr = [], $content = '' ) {
/* the woocommerce hooks and the cart functionality are not initialized during REST / ajax requests, so we do it manually */
if ( \TCB_Utils::is_rest() || wp_doing_ajax() ) {
Main_Woo::init_frontend_woo_functionality();
}
$cart = wc()->cart;
if ( empty( $cart ) ) {
return '';
}
if ( ! is_array( $attr ) ) {
$attr = [];
}
$attr = array_map( static function ( $v ) {
return str_replace( [ '|{|', '|}|' ], [ '[', ']' ], esc_attr( $v ) );
}, $attr );
/* ensure default values */
$attr = array_merge( [
'data-type' => 'icon',
'data-align' => 'left',
'data-trigger' => 'click',
'data-direction' => 'under',
'data-text' => 'Cart',
'data-icon-position' => 'left',
], $attr );
$id = empty( $attr['data-id'] ) ? '' : $attr['data-id'];
unset( $attr['data-id'] );
$classes = [ 'tcb-woo-mini-cart', THRIVE_WRAPPER_CLASS ];
if ( ! empty( $attr['data-class'] ) ) {
$classes = array_merge( $classes, explode( ' ', $attr['data-class'] ) );
}
$in_editor = is_editor_page_raw( true );
if ( $in_editor ) {
$attr['data-shortcode'] = static::SHORTCODE;
}
$cart_content = $cart->get_cart();
/* when in editor and we don't have any products */
$generate_dummy_cart = $in_editor && empty( $cart_content );
if ( $generate_dummy_cart ) {
static::generate_dummy_cart();
}
if ( empty( $content ) ) {
$content = \TCB_Utils::return_part( Main_Woo::get_integration_path( 'assets/mini-cart.svg' ) );
}
$content .= static::get_cart_items_count( $in_editor );
$content = \TCB_Utils::wrap_content( $content, 'div', '', 'tcb-woo-mini-cart-icon' );
$content .=
static::get_cart_price_amount() .
static::get_cart_text( $attr['data-text'] ) .
static::get_cart_items( $in_editor );
if ( $generate_dummy_cart ) {
WC()->cart->empty_cart();
}
return \TCB_Utils::wrap_content( $content, 'div', $id, $classes, $attr );
}
/**
* Render items from the cart using WooCommerce function
*
* @param bool $in_editor
*
* @return string
*/
public static function get_cart_items( $in_editor = false ) {
ob_start();
woocommerce_mini_cart();
$content = ob_get_clean();
if ( $in_editor ) {
$classes = [ 'tcb-woo-mini-cart-items' ];
} else {
/* so it won't be synchronized very fast */
$classes = [ 'widget_shopping_cart_content' ];
}
return \TCB_Utils::wrap_content( $content, 'div', '', $classes );
}
/**
* Return the items that are in the cart at the moment
*
* @param boolean $in_editor
*
* @return string
*/
public static function get_cart_items_count( $in_editor ) {
$count = 0;
$class = [ 'tcb-woo-mini-cart-count' ];
if ( $in_editor ) {
$class[] = 'tcb-selector-not_editable';
$class[] = 'tcb-selector-no_highlight';
}
if ( WC()->cart ) {
$count = WC()->cart->get_cart_contents_count();
}
if ( empty( $count ) ) {
/* don't show zero products ? */
$count = '';
}
return \TCB_Utils::wrap_content( $count, 'div', '', $class );
}
/**
* Get the total price amount for the products in the cart
*
* @return string
*/
public static function get_cart_price_amount() {
if ( WC()->cart ) {
$amount = strip_tags( WC()->cart->get_cart_subtotal() );
} else {
$amount = wc_price( 0 );
}
return \TCB_Utils::wrap_content( $amount, 'div', '', 'tcb-woo-mini-cart-amount' );
}
/**
* Just wrap cart text
*
* @param $text
*
* @return string
*/
public static function get_cart_text( $text ) {
return \TCB_Utils::wrap_content( $text, 'div', '', 'tcb-woo-mini-cart-text' );
}
/**
* In some situations we want to style the cart/checkout and see how it looks even if it's empty.
* Most of the time, we only want to do this in the editor.
* Make sure you empty the cart afterwards!
*
* @param $products_per_page
*/
public static function generate_dummy_cart( $products_per_page = 4 ) {
$dummy_products = get_posts( [
'posts_per_page' => $products_per_page,
'post_type' => 'product',
'orderby' => 'rand',
] );
add_filter( 'woocommerce_is_purchasable', '__return_true' );
foreach ( $dummy_products as $product ) {
try {
WC()->cart->add_to_cart( $product->ID );
} catch ( \Exception $e ) {
if ( $e->getMessage() ) {
wc_add_notice( $e->getMessage(), 'error' );
}
WC()->cart->empty_cart();
}
}
remove_filter( 'woocommerce_is_purchasable', '__return_true' );
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Count
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Count extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Items Count', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-count';
}
/**
* @return array
*/
public function own_components() {
$components = $this->_components( true );
$components['wc-cart-count'] = array(
'config' => array(
'color' => array(
'config' => array(
'default' => '000',
'label' => __( 'Color', 'thrive-cb' ),
),
'extends' => 'ColorPicker',
),
'size' => array(
'config' => array(
'min' => '1',
'max' => '100',
'um' => [ 'px' ],
'label' => __( 'Size', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'horizontal-position' => array(
'config' => array(
'min' => '-50',
'max' => '50',
'um' => [ 'px' ],
'label' => __( 'Horizontal position', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'vertical-position' => array(
'config' => array(
'min' => '-50',
'max' => '50',
'um' => [ 'px' ],
'label' => __( 'Vertical position', 'thrive-cb' ),
),
'extends' => 'Slider',
),
),
);
return $components;
}
}
return new Cart_Count( 'wc-cart-count' );

View File

@@ -0,0 +1,68 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Icon
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Icon extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Icon', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-icon';
}
/**
* @return array
*/
public function own_components() {
$components = $this->_components( true );
$components['wc-cart-icon'] = array(
'config' => array(
'color' => array(
'config' => array(
'default' => '000',
'label' => __( 'Color', 'thrive-cb' ),
),
'extends' => 'ColorPicker',
),
'size' => array(
'css_suffix' => ' > svg',
'config' => array(
'min' => '1',
'max' => '100',
'um' => [ 'px' ],
'label' => __( 'Size', 'thrive-cb' ),
),
'extends' => 'Slider',
),
),
);
$components['borders'] = [ 'hidden' => true ];
return $components;
}
}
return new Cart_Icon( 'wc-cart-icon' );

View File

@@ -0,0 +1,54 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Item_Image
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Item_Image extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Item Image', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.woocommerce-mini-cart-item > a > img';
}
/**
* @return array
*/
public function own_components() {
$components = $this->_components( true );
$components['shadow'] = [
'config' => [
/* sometimes the 'box-shadow' set from woo can be stronger than this, so we give it an '!important' to help it */
'important' => true,
/* only the drop-shadow makes sense for images, disable the rest */
'disabled_controls' => [ 'inner', 'text' ],
],
];
$components['background'] = [ 'hidden' => true ];
return $components;
}
}
return new Cart_Item_Image( 'wc-cart-item-image' );

View File

@@ -0,0 +1,52 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Item_Properties
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Item_Properties extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Item Properties', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-content .woocommerce-mini-cart-item .quantity,.tcb-woo-mini-cart-content .woocommerce-mini-cart-item .variation ';
}
/**
* @return array
*/
public function own_components() {
$components = $this->_components();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( in_array( $control, [ 'css_suffix', 'css_prefix' ] ) ) {
continue;
}
/* make sure typography elements also apply on the link inside the tag */
$components['typography']['config'][ $control ]['css_suffix'] = [ '', ' dt', 'span', 'p' ];
}
return $components;
}
}
return new Cart_Item_Properties( 'wc-cart-item-properties' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Item_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Item_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Item Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.woocommerce-mini-cart-item a:not(.remove_from_cart_button)';
}
/**
* @return array
*/
public function own_components() {
return $this->_components();
}
}
return new Cart_Item_Title( 'wc-cart-item-title' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Item
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Item extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Item', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-content .woocommerce-mini-cart-item';
}
/**
* @return array
*/
public function own_components() {
return $this->_components( true );
}
}
return new Cart_Item( 'wc-cart-item' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Total
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Total extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Total', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-content .woocommerce-mini-cart__total';
}
/**
* @return array
*/
public function own_components() {
return $this->_components();
}
}
return new Cart_Total( 'wc-cart-total' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Wrapper
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Cart_Wrapper extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Container', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.tcb-woo-mini-cart-content .widget_shopping_cart_content';
}
/**
* @return array
*/
public function own_components() {
return $this->_components( true );
}
}
return new Cart_Wrapper( 'wc-cart-wrapper' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Checkout_Button
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Checkout_Button extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Checkout Button', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.woocommerce-mini-cart__buttons .checkout';
}
/**
* @return array
*/
public function own_components() {
return $this->_components();
}
}
return new Checkout_Button( 'wc-checkout-button' );

View File

@@ -0,0 +1,50 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Empty_Cart
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class Empty_Cart extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Empty Cart', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.woocommerce-mini-cart__empty-message';
}
/**
* Set borders to be important
* @return bool
*/
public function has_important_border() {
return true;
}
/**
* @return array
*/
public function own_components() {
return $this->_components( false );
}
}
return new Empty_Cart( 'wc-empty-cart' );

View File

@@ -0,0 +1,42 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\MiniCart;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class View_Cart_Button
*
* @package TCB\Integrations\WooCommerce\Shortcodes\MiniCart
*/
class View_Cart_Button extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'View Cart Button', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.woocommerce-mini-cart__buttons > a:not(.checkout)';
}
/**
* @return array
*/
public function own_components() {
return $this->_components();
}
}
return new View_Cart_Button( 'wc-view-cart-button' );

View File

@@ -0,0 +1,262 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Product_Categories;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Element
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Product_Categories
*/
class Element extends \TCB_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Product Categories', 'thrive-cb' );
}
/**
* @return string
*/
public function icon() {
return 'product-categories';
}
/**
*
* Get element alternate
*
* @return string
*/
public function alternate() {
return 'woocommerce, products, categories';
}
/**
* @return string
*/
public function identifier() {
return Main::IDENTIFIER;
}
/**
* @return array
*/
public function own_components() {
$components = array(
'typography' => [ 'hidden' => true ],
'animation' => [ 'hidden' => true ],
'shadow' => [ 'hidden' => true ],
'responsive' => [ 'hidden' => true ],
'styles-templates' => [ 'hidden' => true ],
'product-categories' => array(
'config' => array(
'Limit' => array(
'config' => array(
'min' => '1',
'max' => '24',
'um' => [],
'label' => __( 'Categories to be displayed', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'Columns' => array(
'config' => array(
'min' => '1',
'max' => '8',
'um' => [],
'label' => __( 'Columns', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'OrderBy' => array(
'config' => array(
'name' => __( 'Order by', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'Name', 'thrive-cb' ),
'value' => 'name',
),
array(
'name' => __( 'ID', 'thrive-cb' ),
'value' => 'id',
),
array(
'name' => __( 'Slug', 'thrive-cb' ),
'value' => 'slug',
),
array(
'name' => __( 'Menu order', 'thrive-cb' ),
'value' => 'menu_order',
),
),
'default' => 'rand',
),
'extends' => 'Select',
),
'Order' => array(
'config' => array(
'name' => __( 'Order', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'A to Z', 'thrive-cb' ),
'value' => 'asc',
),
array(
'name' => __( 'Z to A', 'thrive-cb' ),
'value' => 'desc',
),
),
'default' => 'desc',
),
'extends' => 'Select',
),
'TextLayout' => array(
'config' => array(
'name' => __( 'Text Layout', 'thrive-cb' ),
'full-width' => true,
'buttons' => array(
array(
'value' => 'text_before_image',
'text' => __( 'Before Image', 'thrive-cb' ),
'default' => true,
),
array(
'value' => 'text_on_image',
'text' => __( 'On Image', 'thrive-cb' ),
'default' => true,
),
array(
'value' => 'text_after_image',
'text' => __( 'After Image', 'thrive-cb' ),
),
),
),
'extends' => 'ButtonGroup',
),
'TextPosition' => array(
'config' => array(
'name' => __( 'Text Position', 'thrive-cb' ),
'full-width' => true,
'buttons' => array(
array(
'icon' => 'top',
'value' => 'top',
),
array(
'icon' => 'vertical',
'value' => 'center',
),
array(
'icon' => 'bot',
'value' => 'bottom',
),
),
),
'extends' => 'ButtonGroup',
),
'title-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Title', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'product-number-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Number of products', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'empty-category' => array(
'config' => array(
'name' => '',
'label' => __( 'Hide empty categories', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'Alignment' => array(
'config' => array(
'name' => __( 'Alignment', 'thrive-cb' ),
'buttons' => array(
array(
'icon' => 'a_left',
'value' => 'left',
'tooltip' => __( 'Align Left', 'thrive-cb' ),
),
array(
'icon' => 'a_center',
'value' => 'center',
'default' => true,
'tooltip' => __( 'Align Center', 'thrive-cb' ),
),
array(
'icon' => 'a_right',
'value' => 'right',
'tooltip' => __( 'Align Right', 'thrive-cb' ),
),
),
),
'extends' => 'ButtonGroup',
),
'ImageSize' => array(
'config' => array(
'default' => '100',
'min' => '0',
'max' => '100',
'label' => __( 'Image Size', 'thrive-cb' ),
'um' => [ '%' ],
'css' => 'width',
),
'extends' => 'Slider',
),
'ParentCategory' => array(
'config' => array(
'name' => __( 'Show child categories of a parent category', 'thrive-cb' ),
'full-width' => true,
'options' => array_merge(
array(
array(
'name' => __( 'Display top level categories', 'thrive-cb' ),
'value' => 0,
),
),
Main::get_product_categories_for_select()
),
),
'extends' => 'Select',
),
),
),
'layout' => [
'disabled_controls' => [],
],
);
return $components;
}
/**
* Element category that will be displayed in the sidebar
*
* @return string
*/
public function category() {
return 'WooCommerce';
}
}
return new Element( 'product-categories' );

View File

@@ -0,0 +1,60 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Product_Categories;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Hooks
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Product_Categories
*/
class Hooks {
public static function add() {
add_filter( 'tcb_content_allowed_shortcodes', [ __CLASS__, 'content_allowed_shortcodes_filter' ] );
add_filter( 'tcb_element_instances', [ __CLASS__, 'tcb_element_instances' ] );
}
/**
* Allow the shop shortcode to be rendered in the editor
*
* @param $shortcodes
*
* @return array
*/
public static function content_allowed_shortcodes_filter( $shortcodes ) {
if ( is_editor_page() ) {
$shortcodes[] = Main::SHORTCODE;
}
return $shortcodes;
}
/**
* @param $instances
*
* @return mixed
*/
public static function tcb_element_instances( $instances ) {
$product_categories_element = require_once __DIR__ . '/class-element.php';
$instances[ $product_categories_element->tag() ] = $product_categories_element;
$files = array_diff( scandir( __DIR__ . '/sub-elements' ), [ '.', '..' ] );
foreach ( $files as $file ) {
$instance = require_once __DIR__ . '/sub-elements/' . $file;
$instances[ $instance->tag() ] = $instance;
}
return $instances;
}
}

View File

@@ -0,0 +1,199 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Product_Categories;
use TCB\Integrations\WooCommerce\Main as Main_Woo;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Main
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Product_Categories
*/
class Main {
const SHORTCODE = 'tcb_woo_product_categories';
const IDENTIFIER = '.tcb-woo-product-categories';
public static function init() {
add_shortcode( static::SHORTCODE, [ __CLASS__, 'render' ] );
require_once __DIR__ . '/class-hooks.php';
Hooks::add();
}
/**
* @param array $attr
*
* @return string
*/
public static function render( $attr = [] ) {
/* the woocommerce hooks are not initialized during REST / ajax requests, so we do it manually */
if ( \TCB_Utils::is_rest() || wp_doing_ajax() ) {
Main_Woo::init_frontend_woo_functionality();
}
$in_editor = is_editor_page_raw( true );
static::before_render( $attr, $in_editor );
$content = \WC_Shortcodes::product_categories( $attr );
static::after_render( $attr, $in_editor );
$classes = array( str_replace( '.', '', static::IDENTIFIER ), THRIVE_WRAPPER_CLASS );
if ( $in_editor ) {
$classes[] = 'tcb-selector-no_save tcb-child-selector-no_icons';
} else {
/* only keep a few attributes on the frontend */
$attr = array_intersect_key( $attr, [
'align-items' => '',
'text-layout' => '',
'text-position' => '',
'css' => '',
] );
}
$data = [];
foreach ( $attr as $key => $value ) {
$data[ 'data-' . $key ] = esc_attr( $value );
}
return \TCB_Utils::wrap_content( $content, 'div', '', $classes, $data );
}
/**
* Update default attributes and prepare some filters and variables
*
* @param $attr
* @param $in_editor
*/
public static function before_render( &$attr, $in_editor ) {
$attr = array_merge( [
'limit' => 4,
'columns' => 4,
'hide_empty' => 1,
'orderby' => 'name',
'order' => 'asc',
'ids' => '',
'parent' => 0,
'align-items' => 'center',
'text-layout' => 'text_on_image',
'text-position' => 'center',
], is_array( $attr ) ? $attr : [] );
/*
* Fix for an earlier mistake, or maybe something that WooCommerce changed since then:
* The default value for 'parent' should be 0, not '', otherwise
* all the product categories are displayed, not only the top-level ones.
*/
if ( $attr['parent'] === '' ) {
$attr['parent'] = 0;
}
if ( ! $in_editor && ! empty( $attr['hide-title'] ) ) {
/* by removing this action we actually hide the title; the action is added back in after_render() */
remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title' );
}
/* add our custom text wrapper through woo actions */
add_action( 'woocommerce_before_subcategory_title', [ __CLASS__, 'open_thrive_text_wrapper' ] );
add_action( 'woocommerce_after_subcategory_title', [ __CLASS__, 'close_thrive_text_wrapper' ], 12 );
/* remove the default product category count, ( we are adding a custom implementation through the next filter ) */
add_filter( 'woocommerce_subcategory_count_html', [ __CLASS__, 'remove_default_product_count' ] );
if ( $in_editor || empty( $attr['hide-product-number'] ) ) {
add_action( 'woocommerce_after_subcategory_title', [ __CLASS__, 'add_thrive_product_count' ], 11 );
}
}
/**
* @param $attr
* @param $in_editor
*/
public static function after_render( $attr, $in_editor ) {
if ( ! $in_editor && ! empty( $attr['hide-title'] ) ) {
/* re-add the action that we removed so we don't affect other product categories */
add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title' );
}
/* remove our custom text wrapper */
remove_action( 'woocommerce_before_subcategory_title', [ __CLASS__, 'open_thrive_text_wrapper' ] );
remove_action( 'woocommerce_after_subcategory_title', [ __CLASS__, 'close_thrive_text_wrapper' ], 12 );
/* remove our 'product count removal' filter */
remove_filter( 'woocommerce_subcategory_count_html', [ __CLASS__, 'remove_default_product_count' ] );
if ( $in_editor || empty( $attr['hide-product-number'] ) ) {
/* remove our custom product count implementation */
remove_action( 'woocommerce_after_subcategory_title', [ __CLASS__, 'add_thrive_product_count' ], 11 );
}
}
public static function open_thrive_text_wrapper() {
echo '<div class="thrive-product-category-text-wrapper">';
}
public static function close_thrive_text_wrapper() {
echo '</div>';
}
/**
* Remove the default product category count, so we can add our custom implementation.
*
* @param $product_count_html
*
* @return string
* @see add_thrive_product_count
*
*/
public static function remove_default_product_count( $product_count_html ) {
return '';
}
/**
* Custom 'number of product categories' element
*
* @param $category
*/
public static function add_thrive_product_count( $category ) {
if ( $category->count > 0 ) {
echo \TCB_Utils::wrap_content( $category->count . ' products', 'p', '', 'thrive-product-category-count' ); //phpcs:ignore
}
}
/**
* Get all the product categories and format them to be select-friendly
*
* @return array
*/
public static function get_product_categories_for_select() {
$product_categories = apply_filters(
'woocommerce_product_categories',
get_terms( 'product_cat' )
);
$select_options = array_map( static function ( $item ) {
return [
'name' => $item->name,
'value' => $item->term_id,
];
}, $product_categories );
return array_values( $select_options );
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Count
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Category_Count extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Category Count', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
return '.thrive-product-category-count';
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['typography'] = Main::get_general_typography_config();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
}
return new Product_Category_Count( 'product-category-count' );

View File

@@ -0,0 +1,72 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Image
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Category_Image extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Category Thumbnail', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
return '.product-category a img';
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
/* only the layout, borders and shadows are visible */
$components = [
'typography' => [ 'hidden' => true ],
'background' => [ 'hidden' => true ],
'animation' => [ 'hidden' => true ],
'responsive' => [ 'hidden' => true ],
'styles-templates' => [ 'hidden' => true ],
'shadow' => [
'config' => [
/* sometimes the 'box-shadow' set from woo can be stronger than this, so we give this an '!important' to help it */
'important' => true,
/* only the drop-shadow makes sense for images, disable the rest */
'disabled_controls' => [ 'inner', 'text' ],
],
],
];
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
return $components;
}
}
return new Product_Category_Image( 'product-category-image' );

View File

@@ -0,0 +1,70 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Product_Categories;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Text_Wrapper
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Product_Categories
*/
class Product_Category_Text_Wrapper extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Category Text Container', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
return '.thrive-product-category-text-wrapper';
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* The product category has hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment' ];
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['typography']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return $components;
}
}
return new Product_Category_Text_Wrapper( 'product-category-text-wrapper' );

View File

@@ -0,0 +1,81 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Category_Title extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Category Title', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
return '.woocommerce-loop-category__title';
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['typography'] = Main::get_general_typography_config();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
/**
* @return bool
*/
public function has_hover_state() {
return true;
}
}
return new Product_Category_Title( 'product-category-title' );

View File

@@ -0,0 +1,71 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Product_Categories;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Product_Categories
*/
class Product_Category extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Category', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
return '.product-category';
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* The product category has hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['typography']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return $components;
}
}
return new Product_Category( 'product-category' );

View File

@@ -0,0 +1,354 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Element
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Element extends \TCB_Cloud_Template_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Shop', 'thrive-cb' );
}
/**
* @return string
*/
public function icon() {
return 'shop';
}
/**
*
* Get element alternate
*
* @return string
*/
public function alternate() {
return 'woocommerce, products';
}
/**
* @return string
*/
public function identifier() {
return Main::IDENTIFIER;
}
/**
* @return bool
*/
public function is_placeholder() {
return false;
}
/**
* Show/hide this element ( right now it's being hidden on the shop templates from TTB )
*
* @return bool
*/
public function hide() {
return apply_filters( 'tcb_woo_shop_hide_element', false );
}
/**
* @return array
*/
public function own_components() {
$components = array(
'typography' => [ 'hidden' => true ],
'animation' => [ 'hidden' => true ],
'shadow' => [ 'hidden' => true ],
'responsive' => [ 'hidden' => true ],
'styles-templates' => [ 'hidden' => true ],
'shop' => array(
'config' => array(
'Limit' => array(
'config' => array(
'min' => '1',
'max' => '24',
'um' => [],
'label' => __( 'Products per page', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'Columns' => array(
'config' => array(
'min' => '1',
'max' => '8',
'um' => [],
'label' => __( 'Columns', 'thrive-cb' ),
),
'extends' => 'Slider',
),
'OrderBy' => array(
'config' => array(
'name' => __( 'Order by', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'Product title', 'thrive-cb' ),
'value' => 'title',
),
array(
'name' => __( 'Popularity', 'thrive-cb' ),
'value' => 'popularity',
),
array(
'name' => __( 'Product ID', 'thrive-cb' ),
'value' => 'id',
),
array(
'name' => __( 'Published date', 'thrive-cb' ),
'value' => 'date',
),
array(
'name' => __( 'Last modified date', 'thrive-cb' ),
'value' => 'modified',
),
array(
'name' => __( 'Menu order', 'thrive-cb' ),
'value' => 'menu_order',
),
array(
'name' => __( 'Price', 'thrive-cb' ),
'value' => 'price',
),
array(
'name' => __( 'Random', 'thrive-cb' ),
'value' => 'rand',
),
),
'default' => 'rand',
),
'extends' => 'Select',
),
'Order' => array(
'config' => array(
'name' => __( 'Order', 'thrive-cb' ),
'options' => array(
array(
'name' => __( 'ASC', 'thrive-cb' ),
'value' => 'asc',
),
array(
'name' => __( 'DESC', 'thrive-cb' ),
'value' => 'desc',
),
),
'default' => 'desc',
),
'extends' => 'Select',
),
'result-count-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Result count', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'catalog-ordering-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Catalog ordering', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'sale-flash-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Sale flash ', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'title-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Title', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'rating-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Rating', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'price-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Price', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'cart-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Add to cart', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'pagination-visibility' => array(
'config' => array(
'name' => '',
'label' => __( 'Pagination', 'thrive-cb' ),
'default' => true,
),
'extends' => 'Switch',
),
'Alignment' => array(
'config' => array(
'name' => __( 'Alignment', 'thrive-cb' ),
'buttons' => array(
array(
'icon' => 'a_left',
'value' => 'left',
'tooltip' => __( 'Align Left', 'thrive-cb' ),
),
array(
'icon' => 'a_center',
'value' => 'center',
'default' => true,
'tooltip' => __( 'Align Center', 'thrive-cb' ),
),
array(
'icon' => 'a_right',
'value' => 'right',
'tooltip' => __( 'Align Right', 'thrive-cb' ),
),
),
),
'extends' => 'ButtonGroup',
),
'ImageSize' => array(
'config' => array(
'default' => '100',
'min' => '0',
'max' => '100',
'label' => __( 'Image Size', 'thrive-cb' ),
'um' => [ '%' ],
'css' => 'width',
),
'extends' => 'Slider',
),
'cat_operator' => array(
'config' => array(
'name' => __( 'Category operator', 'thrive-cb' ),
'full-width' => true,
'buttons' => array(
array(
'text' => __( 'Any', 'thrive-cb' ),
'value' => 'in',
),
array(
'text' => __( 'Exclude', 'thrive-cb' ),
'value' => 'not in',
),
array(
'text' => __( 'All', 'thrive-cb' ),
'value' => 'and',
),
),
),
'extends' => 'ButtonGroup',
),
'tag_operator' => array(
'config' => array(
'name' => __( 'Tag operator', 'thrive-cb' ),
'full-width' => true,
'buttons' => array(
array(
'text' => __( 'Any', 'thrive-cb' ),
'value' => 'in',
),
array(
'text' => __( 'Exclude', 'thrive-cb' ),
'value' => 'not in',
),
array(
'text' => __( 'All', 'thrive-cb' ),
'value' => 'and',
),
),
),
'extends' => 'ButtonGroup',
),
'taxonomy' => array(
'config' => array(
'name' => __( 'Taxonomy', 'thrive-cb' ),
'full-width' => true,
'options' => array_merge(
array(
array(
'name' => __( 'None', 'thrive-cb' ),
'value' => '',
'disabled' => true,
),
),
Main::get_product_taxonomies()
),
),
'extends' => 'Select',
),
'terms_operator' => array(
'config' => array(
'name' => __( 'Terms operator', 'thrive-cb' ),
'full-width' => true,
'buttons' => array(
array(
'text' => __( 'Any', 'thrive-cb' ),
'value' => 'in',
),
array(
'text' => __( 'Exclude', 'thrive-cb' ),
'value' => 'not in',
),
array(
'text' => __( 'All', 'thrive-cb' ),
'value' => 'and',
),
),
),
'extends' => 'ButtonGroup',
),
),
),
'layout' => [
'disabled_controls' => [],
],
);
return $components;
}
/**
* Element category that will be displayed in the sidebar
*
* @return string
*/
public function category() {
return 'WooCommerce';
}
}
return new Element( 'shop' );

View File

@@ -0,0 +1,78 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Hooks
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Hooks {
public static function add() {
add_filter( 'tcb_content_allowed_shortcodes', [ __CLASS__, 'content_allowed_shortcodes_filter' ] );
add_filter( 'tcb_element_instances', [ __CLASS__, 'tcb_element_instances' ] );
add_filter( 'woocommerce_pagination_args', [ __CLASS__, 'woocommerce_pagination_args' ] );
}
/**
* Allow the shop shortcode to be rendered in the editor
*
* @param $shortcodes
*
* @return array
*/
public static function content_allowed_shortcodes_filter( $shortcodes ) {
if ( is_editor_page() ) {
$shortcodes[] = Main::SHORTCODE;
}
return $shortcodes;
}
/**
* Make the woo pagination think we're on the second page while in the editor ( so we can style the previous navigation element )
*
* @param $args
*
* @return array
*/
public static function woocommerce_pagination_args( $args ) {
if ( is_editor_page_raw( true ) && $args['total'] >= 2 ) {
$args['current'] = 2;
}
return $args;
}
/**
* @param $instances
*
* @return mixed
*/
public static function tcb_element_instances( $instances ) {
$shop_element = require_once __DIR__ . '/class-element.php';
$instances[ $shop_element->tag() ] = $shop_element;
$files = array_diff( scandir( __DIR__ . '/sub-elements' ), [ '.', '..' ] );
foreach ( $files as $file ) {
$instance = require_once __DIR__ . '/sub-elements/' . $file;
$instances[ $instance->tag() ] = $instance;
}
return $instances;
}
}

View File

@@ -0,0 +1,355 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
use TCB\Integrations\WooCommerce\Main as Woo_Main;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Main
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Main {
const DEFAULT_PRODUCTS_TO_DISPLAY = 8;
const SHORTCODE = 'tcb_woo_shop';
const PATH = 'classes/shortcodes/shop/';
const IDENTIFIER = '.tcb-woo-shop';
/**
* Hooks used by WooCommerce for displaying various components on the shop page
*/
public static $shop_content_hooks = [
'sale-flash' => [
'tag' => 'woocommerce_before_shop_loop_item_title',
'callback' => 'woocommerce_show_product_loop_sale_flash',
'priority' => 10,
],
'result-count' => [
'tag' => 'woocommerce_before_shop_loop',
'callback' => 'woocommerce_result_count',
'priority' => 20,
],
'catalog-ordering' => [
'tag' => 'woocommerce_before_shop_loop',
'callback' => 'woocommerce_catalog_ordering',
'priority' => 30,
],
'title' => [
'tag' => 'woocommerce_shop_loop_item_title',
'callback' => 'woocommerce_template_loop_product_title',
'priority' => 10,
],
'rating' => [
'tag' => 'woocommerce_after_shop_loop_item_title',
'callback' => 'woocommerce_template_loop_rating',
'priority' => 5,
],
'price' => [
'tag' => 'woocommerce_after_shop_loop_item_title',
'callback' => 'woocommerce_template_loop_price',
'priority' => 10,
],
'cart' => [
'tag' => 'woocommerce_after_shop_loop_item',
'callback' => 'woocommerce_template_loop_add_to_cart',
'priority' => 10,
],
'pagination' => [
'tag' => 'woocommerce_after_shop_loop',
'callback' => 'woocommerce_pagination',
'priority' => 10,
],
];
public static function init() {
add_shortcode( static::SHORTCODE, [ __CLASS__, 'render' ] );
require_once __DIR__ . '/class-hooks.php';
Hooks::add();
}
/**
* @param array $attr
*
* @return string
*/
public static function render( $attr = [] ) {
$classes = [ 'tcb-woo-shop', THRIVE_WRAPPER_CLASS ];
static::before_render( $attr );
$in_editor = is_editor_page_raw( true );
if ( ! $in_editor ) {
foreach ( static::$shop_content_hooks as $key => $hook ) {
if ( ! empty( $attr[ 'hide-' . $key ] ) ) {
/* by removing this action we actually hide the element */
remove_action( $hook['tag'], $hook['callback'], $hook['priority'] );
}
}
}
/* Woo has some logic based on using $GLOBALS['post'], which we don't have during REST, so we set it to null as a workaround for Woo */
if ( \TCB_Utils::is_rest() && ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
}
$products = new \WC_Shortcode_Products( $attr );
$content = $products->get_content();
if ( ! $in_editor ) {
foreach ( static::$shop_content_hooks as $key => $hook ) {
if ( ! empty( $attr[ 'hide-' . $key ] ) ) {
/* add the actions back */
add_action( $hook['tag'], $hook['callback'], $hook['priority'] );
}
}
}
static::after_render( $attr );
$id = empty( $attr['id'] ) ? '' : $attr['id'];
unset( $attr['id'] );
if ( $in_editor ) {
$classes[] = 'tcb-selector-no_save tcb-child-selector-no_icons';
} else {
/* only keep a few attributes on the frontend */
$attr = array_intersect_key( $attr, [
'align-items' => '',
'css' => '',
] );
}
$data = [];
foreach ( $attr as $key => $value ) {
$data[ 'data-' . $key ] = esc_attr( $value );
}
return \TCB_Utils::wrap_content( $content, 'div', $id, $classes, $data );
}
/**
* Update default attributes and prepare some filters and variables
*
* @param $attr
*/
public static function before_render( &$attr ) {
$attr = array_merge( array(
'limit' => static::DEFAULT_PRODUCTS_TO_DISPLAY,
'columns' => 4,
'orderby' => 'date',
'order' => 'desc',
'paginate' => true,
'cache' => 'false',
'hide-result-count' => 0,
'hide-catalog-ordering' => 1,
'hide-sale-flash' => 0,
'hide-title' => 0,
'hide-price' => 0,
'hide-rating' => 0,
'hide-cart' => 0,
'hide-pagination' => 0,
'ids' => '',
'category' => '',
'cat_operator' => 'in', /* 'in', 'not in', 'and' */
'taxonomy' => '',
'terms' => '',
'terms_operator' => 'in', /* 'in', 'not in', 'and' */
'tag' => '',
'tag_operator' => 'in', /* 'in', 'not in', 'and' */
'align-items' => 'center',
'ct' => 'shop-0',
'ct-name' => esc_html__( 'Original Shop', 'thrive-cb' ),
), is_array( $attr ) ? $attr : [] );
if ( ! empty( $attr['taxonomy'] ) ) {
$attr['attribute'] = $attr['taxonomy'];
}
/* the 'tag' attribute accepts only tag slugs instead of IDs, so we temporarily change the format */
if ( ! empty( $attr['tag'] ) ) {
$attr['temp_tag'] = $attr['tag'];
$tag_slugs = [];
foreach ( explode( ',', $attr['tag'] ) as $tag ) {
$term = get_term( $tag );
if ( ! empty( $term ) && ! is_wp_error( $term ) ) {
$tag_slugs[] = $term->slug;
}
}
$attr['tag'] = implode( ',', $tag_slugs );
}
/* the default WooCommerce template also displays the title, but we don't need/want that */
add_filter( 'woocommerce_show_page_title', '__return_false' );
/**
* fix for a woocommerce catalog ordering glitch
* 'Sort by price - low to high' has 'price' as an option value, but needs 'price-asc' in woocommerce backend
*
* @see parse_query_args() from class-wc-shortcode-products.php
*/
if ( ! empty( $_GET['orderby'] ) && $_GET['orderby'] === 'price' ) {
/* the fix is to manually set the order attribute when 'price' is present in the query args */
$attr['order'] = 'asc';
}
}
/**
* Some attributes were changed temporarily in before_render, we revert to their original names here
*
* @param $attr
*/
public static function after_render( &$attr ) {
if ( ! empty( $attr['temp_tag'] ) ) {
$attr['tag'] = $attr['temp_tag'];
unset ( $attr['temp_tag'] );
}
if ( ! empty( $attr['attribute'] ) ) {
$attr['taxonomy'] = $attr['attribute'];
unset ( $attr['attribute'] );
}
}
/**
* @return array
*/
public static function get_product_taxonomies() {
$all = get_object_taxonomies( Woo_Main::POST_TYPE, 'object' );
$taxonomies = array_map( static function ( $item ) {
return [
'name' => $item->label,
'value' => $item->name,
];
}, $all );
$taxonomies = array_filter( $taxonomies, function ( $taxonomy ) {
/* we only return attribute-taxonomies ( they are prefixed with 'pa_' ) */
$is_attribute_taxonomy = strpos( $taxonomy['value'], 'pa_' ) !== false;
$terms = get_terms( [
'taxonomy' => $taxonomy['value'],
'hide_empty' => false,
] );
return $is_attribute_taxonomy && ( count( $terms ) > 0 ); /* we only return taxonomies that have terms inside them */
} );
return array_values( $taxonomies );
}
/**
* @param $identifier
*
* @return mixed|void
*/
public static function get_shop_element_identifier( $identifier ) {
return apply_filters( 'tcb_woo_shop_identifier', Main::IDENTIFIER ) . ' ' . $identifier;
}
/**
* @var string[]
*/
public static $sub_elements = array(
'product-button' => '.product a.button',
'product-image' => '.product .woocommerce-loop-product__link > img',
'product-onsale' => '.product .onsale',
'product-price' => '.product .price',
'product-rating' => '.product .star-rating',
'product-title' => '.product .woocommerce-loop-product__title',
'product-wrapper' => '.type-product.product',
'product-result-count' => '.woocommerce-result-count',
'product-catalog-ordering' => '.woocommerce-ordering',
'product-pagination' => '.woocommerce-pagination',
'product-pagination-item' => 'li .page-numbers:not(.current):not(.prev):not(.next)',
'product-pagination-current-item' => '.page-numbers.current',
'product-pagination-prev' => '.page-numbers.prev',
'product-pagination-next' => '.page-numbers.next',
);
/**
* @param string $tag
*
* @return string|string[]
*/
public static function get_sub_element_identifier( $tag = '' ) {
return empty( $tag ) ? static::$sub_elements : static::$sub_elements[ $tag ];
}
/**
* @return array[]
*/
public static function get_general_typography_config() {
return [
'disabled_controls' => [
'.tve-advanced-controls',
'p_spacing',
'h1_spacing',
'h2_spacing',
'h3_spacing',
],
'config' => [
'css_suffix' => '',
'css_prefix' => '',
'TextShadow' => [
'css_suffix' => '',
'css_prefix' => '',
],
'FontColor' => [
'css_suffix' => '',
'css_prefix' => '',
],
'FontSize' => [
'css_suffix' => '',
'css_prefix' => '',
],
'TextStyle' => [
'css_suffix' => '',
'css_prefix' => '',
],
'LineHeight' => [
'css_suffix' => '',
'css_prefix' => '',
],
'FontFace' => [
'css_suffix' => '',
'css_prefix' => '',
],
'LetterSpacing' => [
'css_suffix' => '',
'css_prefix' => '',
],
'TextAlign' => [
'css_suffix' => '',
'css_prefix' => '',
],
'TextTransform' => [
'css_suffix' => '',
'css_prefix' => '',
],
],
];
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Button
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Button extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Add to cart', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-button' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* Add to cart button has hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['typography'] = Main::get_general_typography_config();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
/* this is less specific because the color property has to be changed while the cart button does the loading animation */
$components['typography']['config']['FontColor']['important'] = false;
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
return $components;
}
}
return new Product_Button( 'product-button' );

View File

@@ -0,0 +1,87 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Catalog_Ordering
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Catalog_Ordering extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Catalog Ordering', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-catalog-ordering' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['background']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['typography'] = Main::get_general_typography_config();
$components['typography']['disabled_controls'] = array_merge( $components['typography']['disabled_controls'], [ 'Alignment' ] );
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = ' select';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['layout']['config']['MarginAndPadding']['padding_to'] = ' select';
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
$components['borders'] = [
'config' => [
'css_suffix' => ' select',
],
];
return $components;
}
}
return new Product_Catalog_Ordering( 'product-catalog-ordering' );

View File

@@ -0,0 +1,74 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Image
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Image extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Image', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-image' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
/* only the layout, borders and shadows are visible */
$components = [
'typography' => [ 'hidden' => true ],
'background' => [ 'hidden' => true ],
'animation' => [ 'hidden' => true ],
'responsive' => [ 'hidden' => true ],
'styles-templates' => [ 'hidden' => true ],
'shadow' => [
'config' => [
'disabled_controls' => [ 'inner', 'text' ],
],
],
];
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['borders']['config']['Borders']['important'] = true;
$components['borders']['config']['Corners']['important'] = true;
return $components;
}
}
return new Product_Image( 'product-image' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Onsale
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Onsale extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Sale', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-onsale' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['typography'] = Main::get_general_typography_config();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
}
return new Product_Onsale( 'product-onsale' );

View File

@@ -0,0 +1,74 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Pagination_Current_Item
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Pagination_Current_Item extends \TCB_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Active Page', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-pagination-current-item' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['typography'] = Main::get_general_typography_config();
$components['typography']['config']['css_suffix'] = '';
$components['typography']['disabled_controls'] = [ 'TextTransform', 'TextAlign', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
}
}
$components['typography']['config']['FontColor']['important'] = true;
$components['typography']['config']['FontSize']['important'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return $components;
}
}
return new Product_Pagination_Current_Item( 'product-pagination-current-item' );

View File

@@ -0,0 +1,83 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Pagination_Item
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Pagination_Item extends \TCB_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Page Number', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-pagination-item' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['typography'] = Main::get_general_typography_config();
$components['typography']['config']['css_suffix'] = '';
$components['typography']['disabled_controls'] = [ 'TextTransform', 'TextAlign', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
}
}
$components['typography']['config']['FontColor']['important'] = true;
$components['typography']['config']['FontSize']['important'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['borders']['config']['Corners']['important'] = true;
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return $components;
}
}
return new Product_Pagination_Item( 'product-pagination-item' );

View File

@@ -0,0 +1,50 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Pagination_Next
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Pagination_Next extends Product_Pagination_Item {
/**
* @return string
*/
public function name() {
return __( 'Prev/Next Item', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-pagination-next' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* @return array
*/
public function own_components() {
$components = parent::own_components();
$components['typography']['disabled_controls'] = array_merge( $components['typography']['disabled_controls'], [ 'TextStyle' ] );
return $components;
}
}
return new Product_Pagination_Next( 'product-pagination-next' );

View File

@@ -0,0 +1,50 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Pagination_Prev
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Pagination_Prev extends Product_Pagination_Item {
/**
* @return string
*/
public function name() {
return __( 'Prev/Next Item', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-pagination-prev' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* @return array
*/
public function own_components() {
$components = parent::own_components();
$components['typography']['disabled_controls'] = array_merge( $components['typography']['disabled_controls'], [ 'TextStyle' ] );
return $components;
}
}
return new Product_Pagination_Prev( 'product-pagination-prev' );

View File

@@ -0,0 +1,94 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Pagination
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Pagination extends \TCB_Element_Abstract {
/**
* @return string
*/
public function name() {
return __( 'Pagination', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-pagination' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['typography']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return array_merge( $components, $this->group_component() );
}
/**
* Group Edit Properties
*
* @return array|bool
*/
public function has_group_editing() {
return array(
'select_values' => array(
array(
'value' => 'product_pagination_navigation_items',
'selector' => '.tcb-prev-next',
'name' => __( 'Prev/Next Items', 'thrive-cb' ),
'singular' => __( 'Prev/Next Item', 'thrive-cb' ),
'no_unlock' => true,
),
array(
'value' => 'product_pagination_numbered_items',
'selector' => Main::get_sub_element_identifier( 'product-pagination-item' ),
'name' => __( 'Grouped Page Numbers', 'thrive-cb' ),
'singular' => __( 'Page Number', 'thrive-cb' ),
'no_unlock' => true,
),
),
);
}
}
return new Product_Pagination( 'product-pagination' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Price extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Price', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-price' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['typography'] = Main::get_general_typography_config();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
}
return new Product_Price( 'product-price' );

View File

@@ -0,0 +1,85 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Rating
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Rating extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Star Rating', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-rating' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['product-star-rating'] = array(
'config' => array(
'color' => array(
'config' => array(
'default' => '000',
'label' => __( 'Color', 'thrive-cb' ),
),
'extends' => 'ColorPicker',
),
'size' => array(
'config' => array(
'min' => '1',
'max' => '100',
'um' => [ 'px' ],
'label' => __( 'Size', 'thrive-cb' ),
),
'extends' => 'Slider',
),
),
);
$components['typography']['hidden'] = true;
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Width', 'Height', 'Display', 'Alignment', '.tve-advanced-controls' ];
return $components;
}
}
return new Product_Rating( 'product-rating' );

View File

@@ -0,0 +1,78 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Result_Count
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Result_Count extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Result Count', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-result-count' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['typography'] = Main::get_general_typography_config();
$components['typography']['disabled_controls'] = array_merge( $components['typography']['disabled_controls'], [ 'Alignment' ] );
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
}
return new Product_Result_Count( 'product-result-count' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Title extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product Title', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-title' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['animation']['hidden'] = true;
$components['shadow']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['typography'] = Main::get_general_typography_config();
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
$components['typography']['config'][ $control ]['important'] = true;
}
}
$components['typography']['config']['css_suffix'] = '';
$components['typography']['config']['css_prefix'] = '';
return $components;
}
}
return new Product_Title( 'product-title' );

View File

@@ -0,0 +1,73 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Shop;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Wrapper
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Shop
*/
class Product_Wrapper extends \TCB_Element_Abstract {
/**
* Element name
*
* @return string|void
*/
public function name() {
return __( 'Product', 'thrive-cb' );
}
/**
* WordPress element identifier
*
* @return string
*/
public function identifier() {
$identifier = Main::get_sub_element_identifier( 'product-wrapper' );
return Main::get_shop_element_identifier( $identifier );
}
/**
* Element is not visible in the sidebar
*
* @return bool
*/
public function hide() {
return true;
}
/**
* Add to cart button has hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
public function own_components() {
$components = parent::own_components();
$components['layout']['disabled_controls'] = [ 'Display', 'Alignment', '.tve-advanced-controls' ];
$components['animation']['hidden'] = true;
$components['responsive']['hidden'] = true;
$components['typography']['hidden'] = true;
$components['styles-templates']['hidden'] = true;
return $components;
}
}
return new Product_Wrapper( 'product-wrapper' );

View File

@@ -0,0 +1,60 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Abstract_Sub_Element
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Abstract_Sub_Element extends \TCB_Element_Abstract {
/**
* All sub elements are not visible
*
* @return bool
*/
public function hide() {
return true;
}
/**
* Get the components that are specific to the widgets' editable elements
*
* @return array
*/
public function _components() {
$components = $this->general_components();
$components['animation'] = [ 'hidden' => true ];
$components['responsive'] = [ 'hidden' => true ];
$components['styles-templates'] = [ 'hidden' => true ];
$components['background'] = [ 'hidden' => true ];
$components['layout'] = [ 'hidden' => true ];
$components['shadow'] = [ 'hidden' => true ];
$components['borders'] = [ 'hidden' => true ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = '';
}
}
return $components;
}
/**
* @return array
*/
public function own_components() {
return $this->_components();
}
}

View File

@@ -0,0 +1,239 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Widgets
*
* @package TCB\Integrations\WooCommerce
*/
class Widgets {
public static function init() {
static::add_actions();
static::add_filters();
}
public static function add_actions() {
add_action( 'tcb_ajax_before_widget_render', [ __CLASS__, 'tcb_ajax_before_widget_render' ] );
add_action( 'tcb_before_widget_render', [ __CLASS__, 'tcb_before_widget_render' ] );
}
public static function add_filters() {
add_filter( 'tve_include_widgets_in_editor', '__return_true' );
add_filter( 'tcb_editor_widgets', [ __CLASS__, 'tcb_editor_widgets' ], 10 );
add_filter( 'tcb_widget_element_category', [ __CLASS__, 'tcb_widget_element_category' ], 10, 2 );
add_filter( 'tcb_widget_element_icon', [ __CLASS__, 'tcb_widget_element_icon' ], 10, 2 );
add_filter( 'tcb_widget_data_widget_woocommerce_widget_cart', [ __CLASS__, 'cart_widget_data' ] );
add_filter( 'sidebars_widgets', [ __CLASS__, 'sidebars_widgets' ] );
add_filter( 'tcb_element_instances', [ __CLASS__, 'tcb_element_instances' ] );
}
/**
* Filter allowed widgets in the editor
*
* @param $widgets
*
* @return mixed
*/
public static function tcb_editor_widgets( $widgets ) {
$widgets = array_filter( $widgets, static function ( $widget ) {
/* @var \WP_Widget $widget */
return strpos( $widget->id_base, 'woocommerce' ) !== false && strpos( $widget->id_base, 'filter' ) === false;
} );
return $widgets;
}
/**
* Group WooCommerce widgets in one category
*
* @param string $category
* @param \WP_Widget $widget
*
* @return string
*/
public static function tcb_widget_element_category( $category, $widget ) {
if ( strpos( $widget->id_base, 'woocommerce' ) !== false ) {
$category = 'WooCommerce';
}
return $category;
}
/**
* Custom icons for WooCommerce icons
*
* @param string $icon
* @param \WP_Widget $widget
*
* @return string
*/
public static function tcb_widget_element_icon( $icon, $widget ) {
if ( strpos( $widget->id_base, 'woocommerce' ) !== false ) {
$icon = (string) $widget->id_base;
}
return $icon;
}
/**
* If the cart is empty, temporarily add a few products to the cart so we can show some content in the editor
*
* @param array $data
*
* @return array
*/
public static function cart_widget_data( $data ) {
$woo_cart = wc()->cart->get_cart();
if ( empty( $woo_cart ) ) {
$dummy_products = get_posts( [
'posts_per_page' => 3,
'post_type' => 'product',
'orderby' => 'rand',
] );
foreach ( $dummy_products as $product ) {
try {
WC()->cart->add_to_cart( $product->ID );
} catch ( \Exception $e ) {
if ( $e->getMessage() ) {
wc_add_notice( $e->getMessage(), 'error' );
}
}
}
ob_start();
woocommerce_mini_cart();
$mini_cart = ob_get_clean();
/* replace the empty wrapper with the populated equivalent */
$data['content'] = str_replace(
'<div class="widget_shopping_cart_content"></div>',
'<div class="widget_shopping_cart_content">' . $mini_cart . '</div>',
$data['content'] );
$data['cart_is_empty'] = empty( $woo_cart );
/* empty the cart to remove the products that we just added */
WC()->cart->empty_cart();
}
return $data;
}
/**
* Set the query as being the shop when trying to render widgets
* This action has a dynamic name - @see \TCB_Editor_Ajax::handle()
*/
public static function tcb_ajax_before_widget_render() {
if ( isset( $_GET['widget'] ) && strpos( sanitize_text_field( $_GET['widget'] ), 'woocommerce', true ) !== false && ! empty( $_GET['query'] ) ) {
/** @var \WP_Query */
global $wp_query;
$query_args = map_deep( $_GET['query'], 'sanitize_text_field' );
if ( ! empty( $query_args['p'] ) ) {
/* manually set the post type inside the query, otherwise the 'post' post-type gets queried */
$query_args['post_type'] = get_post_type( $query_args['p'] );
}
/* set the global query as the same one that we're editing so we can convert shortcodes better */
$wp_query->query( $query_args );
if ( $wp_query->is_singular() ) {
/* product page */
$wp_query->the_post();
wc_setup_product_data( get_the_ID() );
} else {
/* shop page */
\WooCommerce::instance()->query->product_query( $wp_query );
}
}
}
/**
* Filter for sidebar widgets. On product pages we always want to track recent viewed because widgets can be used outside of the sidebar.
*
* @param array $sidebars_widgets
*
* @return array
*/
public static function sidebars_widgets( $sidebars_widgets ) {
if ( ! is_admin() && is_product() ) {
$sidebars_widgets['dummy-widgets'] = [ 'woocommerce_recently_viewed_products' ];
}
return $sidebars_widgets;
}
/**
* Flush the widget cache before rendering certain widgets
* For instance, when two different Product Widgets are added, if we don't flush the cache after rendering the first widget, then the second widget copies the content of the first one
*
* @param \WC_Widget $widget
*
* @see \WC_Widget::cache_widget()
*/
public static function tcb_before_widget_render( $widget ) {
if ( in_array( $widget->option_name, static::get_cached_widget_keys() ) ) {
$widget->flush_widget_cache();
}
}
/**
* The content of these widgets is being cached, and we want to prevent this because it can duplicate different widgets
*
* @return string[]
*/
public static function get_cached_widget_keys() {
return [
'widget_woocommerce_products',
'widget_woocommerce_top_rated_products',
'widget_woocommerce_recent_reviews',
];
}
/**
* @param $instances
*
* @return mixed
*/
public static function tcb_element_instances( $instances ) {
require_once __DIR__ . '/class-abstract-sub-element.php';
$widgets = array_diff( scandir( __DIR__ . '/sub-elements' ), [ '.', '..' ] );
foreach ( $widgets as $widget ) {
$files = array_diff( scandir( __DIR__ . '/sub-elements/' . $widget ), [ '.', '..' ] );
foreach ( $files as $file ) {
$instance = require_once __DIR__ . '/sub-elements/' . $widget . '/' . $file;
$instances[ $instance->tag() ] = $instance;
}
}
return $instances;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_View_Cart
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Checkout extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Checkout', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart__buttons > a:nth-child(2)';
}
/**
* Whether or not the this element can be edited while under :hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
$components['background'] = [ 'hidden' => false ];
return $components;
}
}
return new Cart_Widget_Checkout( 'wc-cart-widget-checkout' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Price_Subtotal
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Price_Subtotal extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Subtotal', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart__total .woocommerce-Price-amount';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Cart_Widget_Price_Subtotal( 'wc-cart-widget-price-subtotal' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Product_Addon_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Product_Addon_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Addon Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart-item .variation dt';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
return $components;
}
}
return new Cart_Widget_Product_Addon_Title( 'wc-cart-widget-product-addon-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Product_Addon_Value
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Product_Addon_Value extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Addon Value', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart-item .variation dd p';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
return $components;
}
}
return new Cart_Widget_Product_Addon_Value( 'wc-cart-widget-product-addon-value' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Product_Price extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Price', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .product_list_widget .quantity';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Cart_Widget_Product_Price( 'wc-cart-widget-product-price' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Product_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart-item a:not(.remove_from_cart_button)';
}
}
return new Cart_Widget_Product_Title( 'wc-cart-widget-product-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Subtotal extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Subtotal', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .total strong';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign' ];
return $components;
}
}
return new Cart_Widget_Subtotal( 'wc-cart-widget-subtotal' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Cart Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .widget-title';
}
}
return new Cart_Widget_Title( 'wc-cart-widget-title' );

View File

@@ -0,0 +1,55 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Cart_Widget_View_Cart
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Cart_Widget_View_Cart extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'View Cart', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_shopping_cart .woocommerce-mini-cart__buttons > a:first-child';
}
/**
* Whether or not the this element can be edited while under :hover state
*
* @return bool
*/
public function has_hover_state() {
return true;
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
$components['background'] = [ 'hidden' => false ];
return $components;
}
}
return new Cart_Widget_View_Cart( 'wc-cart-widget-view-cart' );

View File

@@ -0,0 +1,51 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Dropdown
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Category_Dropdown extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Category', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_categories .select2-container--default';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['css_suffix'] = [ '', '.select2-selection' ];
}
}
return $components;
}
}
return new Product_Category_Dropdown( 'wc-product-category-dropdown' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Category_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Category Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_categories .widget-title';
}
}
return new Product_Category_Title( 'wc-product-category-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Category
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Category extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Category', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_categories .product-categories li a';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Product_Category( 'wc-product-category' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Search
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Search extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Search Input', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_search .search-field';
}
}
return new Product_Search( 'wc-product-search' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Tag_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Tag_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Tag Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_tag_cloud .widget-title';
}
}
return new Product_Tag_Title( 'wc-product-tag-title' );

View File

@@ -0,0 +1,51 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Product_Tag
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Product_Tag extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Tag', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_product_tag_cloud .tagcloud a';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', '.tve-advanced-controls' ];
foreach ( $components['typography']['config'] as $control => $config ) {
if ( is_array( $config ) ) {
$components['typography']['config'][ $control ]['important'] = true;
}
}
return $components;
}
}
return new Product_Tag( 'wc-product-tag' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_By_Rating_Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_By_Rating_Product_Price extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Price', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_top_rated_products .woocommerce-Price-amount';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Products_By_Rating_Product_Price( 'wc-products-by-rating-product-price' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_By_Rating_Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_By_Rating_Product_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_top_rated_products .product_list_widget a';
}
}
return new Products_By_Rating_Product_Title( 'wc-products-by-rating-product-title' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_By_Rating_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_By_Rating_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Top Rated Products Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_top_rated_products .widget-title';
}
}
return new Products_By_Rating_Title( 'wc-products-by-rating-title' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Review_Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Review_Product_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recent_reviews .product_list_widget a';
}
}
return new Products_Review_Product_Title( 'wc-products-review-product-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Review_Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Review_Product_Price extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Reviewer', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recent_reviews .reviewer';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign' ];
return $components;
}
}
return new Products_Review_Product_Price( 'wc-products-review-reviewer' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Review_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Review_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Recent Reviews Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recent_reviews .widget-title';
}
}
return new Products_Review_Title( 'wc-products-review-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Widget_Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Widget_Product_Price extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Price', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_products .woocommerce-Price-amount';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Products_Widget_Product_Price( 'wc-products-widget-product-price' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Widget_Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Widget_Product_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_products .product_list_widget a';
}
}
return new Products_Widget_Product_Title( 'wc-products-widget-product-title' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Products_Widget_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Products_Widget_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Products Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_products .widget-title';
}
}
return new Products_Widget_Title( 'wc-products-widget-title' );

View File

@@ -0,0 +1,45 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Recently_Viewed_Products_Product_Price
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Recently_Viewed_Products_Product_Price extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Price', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recently_viewed_products .woocommerce-Price-amount';
}
/**
* @return array
*/
public function own_components() {
$components = parent::_components();
$components['typography']['disabled_controls'] = [ 'TextAlign', 'TextTransform', '.tve-advanced-controls' ];
return $components;
}
}
return new Recently_Viewed_Products_Product_Price( 'wc-recently-viewed-products-product-price' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Recently_Viewed_Products_Product_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Recently_Viewed_Products_Product_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Product Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recently_viewed_products .product_list_widget a';
}
}
return new Recently_Viewed_Products_Product_Title( 'wc-recently-viewed-products-product-title' );

View File

@@ -0,0 +1,35 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-visual-editor
*/
namespace TCB\Integrations\WooCommerce\Shortcodes\Widgets;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class Recently_Viewed_Products_Title
*
* @package TCB\Integrations\WooCommerce\Shortcodes\Widgets
*/
class Recently_Viewed_Products_Title extends Abstract_Sub_Element {
/**
* @return string
*/
public function name() {
return __( 'Recently Viewed Products Title', 'thrive-cb' );
}
/**
* @return string
*/
public function identifier() {
return '.widget_recently_viewed_products .widget-title';
}
}
return new Recently_Viewed_Products_Title( 'wc-recently-viewed-products-title' );