Upgarded to 4.17.4
This commit is contained in:
@ -10,6 +10,8 @@
|
||||
* @since 3.29
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Class representing WooCommerce Upsells component.
|
||||
*/
|
||||
@ -21,16 +23,24 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
*/
|
||||
public static $static_props;
|
||||
|
||||
/**
|
||||
* Number of products to be offset.
|
||||
*
|
||||
* @var int Default 0.
|
||||
*/
|
||||
public static $offset = 0;
|
||||
|
||||
/**
|
||||
* Initialize.
|
||||
*/
|
||||
public function init() {
|
||||
$this->name = esc_html__( 'Woo Upsell', 'et_builder' );
|
||||
$this->plural = esc_html__( 'Woo Upsells', 'et_builder' );
|
||||
$this->name = esc_html__( 'Woo Product Upsell', 'et_builder' );
|
||||
$this->plural = esc_html__( 'Woo Product Upsell', 'et_builder' );
|
||||
|
||||
// Use `et_pb_wc_{module}` for all WooCommerce modules.
|
||||
$this->slug = 'et_pb_wc_upsells';
|
||||
$this->vb_support = 'on';
|
||||
$this->slug = 'et_pb_wc_upsells';
|
||||
$this->vb_support = 'on';
|
||||
$this->folder_name = 'et_pb_woo_modules';
|
||||
|
||||
$this->main_css_element = '%%order_class%%';
|
||||
|
||||
@ -38,14 +48,16 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'general' => array(
|
||||
'toggles' => array(
|
||||
'main_content' => et_builder_i18n( 'Content' ),
|
||||
'elements' => et_builder_i18n( 'Elements' ),
|
||||
),
|
||||
),
|
||||
'advanced' => array(
|
||||
'toggles' => array(
|
||||
'overlay' => et_builder_i18n( 'Overlay' ),
|
||||
'image' => et_builder_i18n( 'Image' ),
|
||||
'overlay' => et_builder_i18n( 'Overlay' ),
|
||||
'image' => et_builder_i18n( 'Image' ),
|
||||
// Avoid Text suffix by manually defining the `star` toggle slug.
|
||||
'star' => esc_html__( 'Star Rating', 'et_builder' ),
|
||||
'star' => esc_html__( 'Star Rating', 'et_builder' ),
|
||||
'sale_badge' => esc_html__( 'Sale Badge Text', 'et_builder' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
@ -73,7 +85,8 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'letter_spacing_hover' => '%%order_class%% ul.products li.product:hover .star-rating',
|
||||
),
|
||||
'font_size' => array(
|
||||
'default' => 14,
|
||||
'default' => '14px',
|
||||
'label' => esc_html__( 'Star Rating Size', 'et_builder' ),
|
||||
),
|
||||
'hide_font' => true,
|
||||
'hide_line_height' => true,
|
||||
@ -81,9 +94,6 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'text_align' => array(
|
||||
'label' => esc_html__( 'Star Rating Alignment', 'et_builder' ),
|
||||
),
|
||||
'font_size' => array(
|
||||
'label' => esc_html__( 'Star Rating Size', 'et_builder' ),
|
||||
),
|
||||
'text_color' => array(
|
||||
'label' => esc_html__( 'Star Rating Color', 'et_builder' ),
|
||||
),
|
||||
@ -179,14 +189,29 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'tab_slug' => 'advanced',
|
||||
'toggle_slug' => 'image',
|
||||
),
|
||||
'sale_badge' => array(
|
||||
'css' => array(
|
||||
'main' => array(
|
||||
'border_radii' => '%%order_class%% span.onsale',
|
||||
'border_styles' => '%%order_class%% span.onsale',
|
||||
),
|
||||
'important' => true,
|
||||
),
|
||||
'defaults' => array(
|
||||
'border_radii' => 'on|3px|3px|3px|3px',
|
||||
),
|
||||
'label_prefix' => esc_html__( 'Sale Badge', 'et_builder' ),
|
||||
'tab_slug' => 'advanced',
|
||||
'toggle_slug' => 'sale_badge',
|
||||
),
|
||||
),
|
||||
'box_shadow' => array(
|
||||
'default' => array(
|
||||
'default' => array(
|
||||
'css' => array(
|
||||
'main' => '%%order_class%% .product',
|
||||
),
|
||||
),
|
||||
'image' => array(
|
||||
'image' => array(
|
||||
'label' => esc_html__( 'Image Box Shadow', 'et_builder' ),
|
||||
'option_category' => 'layout',
|
||||
'tab_slug' => 'advanced',
|
||||
@ -200,6 +225,17 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'position' => '',
|
||||
),
|
||||
),
|
||||
'sale_badge' => array(
|
||||
'label' => esc_html__( 'Sale Badge Box Shadow', 'et_builder' ),
|
||||
'option_category' => 'layout',
|
||||
'tab_slug' => 'advanced',
|
||||
'toggle_slug' => 'sale_badge',
|
||||
'css' => array(
|
||||
'main' => '%%order_class%% span.onsale',
|
||||
'overlay' => 'inset',
|
||||
'important' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'margin_padding' => array(
|
||||
'css' => array(
|
||||
@ -240,6 +276,31 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
),
|
||||
),
|
||||
'button' => false,
|
||||
'form_field' => array(
|
||||
'sale_badge' => array(
|
||||
'label' => esc_html__( 'Sale Badge', 'et_builder' ),
|
||||
'background_color' => false,
|
||||
'text_color' => false,
|
||||
'focus_background_color' => false,
|
||||
'focus_text_color' => false,
|
||||
'font_field' => false,
|
||||
'margin_padding' => array(
|
||||
'css' => array(
|
||||
'main' => '%%order_class%% ul.products li.product span.onsale',
|
||||
'important' => array( 'custom_margin', 'custom_padding' ),
|
||||
),
|
||||
'custom_margin' => array(
|
||||
'default' => '0px|0px|0px|0px|false|false',
|
||||
),
|
||||
'custom_padding' => array(
|
||||
'default' => '6px|18px|6px|18px|false|false',
|
||||
),
|
||||
'toggle_slug' => 'sale_badge',
|
||||
),
|
||||
'border_styles' => false,
|
||||
'box_shadow' => false,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$this->custom_css_fields = array(
|
||||
@ -384,6 +445,84 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'mobile_options' => true,
|
||||
'sticky' => true,
|
||||
),
|
||||
'show_name' => array(
|
||||
'label' => esc_html__( 'Show Name', 'et_builder' ),
|
||||
'type' => 'yes_no_button',
|
||||
'option_category' => 'configuration',
|
||||
'options' => array(
|
||||
'on' => esc_html__( 'Yes', 'et_builder' ),
|
||||
'off' => esc_html__( 'No', 'et_builder' ),
|
||||
),
|
||||
'default_on_front' => 'on',
|
||||
'toggle_slug' => 'elements',
|
||||
'description' => esc_html__( 'Turn name on or off.', 'et_builder' ),
|
||||
'mobile_options' => true,
|
||||
'hover' => 'tabs',
|
||||
),
|
||||
'show_image' => array(
|
||||
'label' => esc_html__( 'Show Image', 'et_builder' ),
|
||||
'type' => 'yes_no_button',
|
||||
'option_category' => 'configuration',
|
||||
'options' => array(
|
||||
'on' => esc_html__( 'Yes', 'et_builder' ),
|
||||
'off' => esc_html__( 'No', 'et_builder' ),
|
||||
),
|
||||
'default_on_front' => 'on',
|
||||
'toggle_slug' => 'elements',
|
||||
'description' => esc_html__( 'Turn image on or off.', 'et_builder' ),
|
||||
'mobile_options' => true,
|
||||
'hover' => 'tabs',
|
||||
),
|
||||
'show_price' => array(
|
||||
'label' => esc_html__( 'Show Price', 'et_builder' ),
|
||||
'type' => 'yes_no_button',
|
||||
'option_category' => 'configuration',
|
||||
'options' => array(
|
||||
'on' => esc_html__( 'Yes', 'et_builder' ),
|
||||
'off' => esc_html__( 'No', 'et_builder' ),
|
||||
),
|
||||
'default_on_front' => 'on',
|
||||
'toggle_slug' => 'elements',
|
||||
'description' => esc_html__( 'Turn price on or off.', 'et_builder' ),
|
||||
'mobile_options' => true,
|
||||
'hover' => 'tabs',
|
||||
),
|
||||
'show_rating' => array(
|
||||
'label' => esc_html__( 'Show Rating', 'et_builder' ),
|
||||
'type' => 'yes_no_button',
|
||||
'option_category' => 'configuration',
|
||||
'options' => array(
|
||||
'on' => esc_html__( 'Yes', 'et_builder' ),
|
||||
'off' => esc_html__( 'No', 'et_builder' ),
|
||||
),
|
||||
'default_on_front' => 'on',
|
||||
'toggle_slug' => 'elements',
|
||||
'description' => esc_html__( 'Turn rating on or off.', 'et_builder' ),
|
||||
'mobile_options' => true,
|
||||
'hover' => 'tabs',
|
||||
),
|
||||
'show_sale_badge' => array(
|
||||
'label' => esc_html__( 'Show Sale Badge', 'et_builder' ),
|
||||
'type' => 'yes_no_button',
|
||||
'option_category' => 'configuration',
|
||||
'options' => array(
|
||||
'on' => esc_html__( 'Yes', 'et_builder' ),
|
||||
'off' => esc_html__( 'No', 'et_builder' ),
|
||||
),
|
||||
'default_on_front' => 'on',
|
||||
'toggle_slug' => 'elements',
|
||||
'description' => esc_html__( 'Turn sale badge on or off.', 'et_builder' ),
|
||||
'mobile_options' => true,
|
||||
'hover' => 'tabs',
|
||||
),
|
||||
'offset_number' => ET_Builder_Module_Helper_Woocommerce_Modules::get_field(
|
||||
'offset_number',
|
||||
array(
|
||||
'computed_affects' => array(
|
||||
'__upsells',
|
||||
),
|
||||
)
|
||||
),
|
||||
'__upsells' => array(
|
||||
'type' => 'computed',
|
||||
'computed_callback' => array(
|
||||
@ -396,6 +535,7 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
'posts_number',
|
||||
'columns_number',
|
||||
'orderby',
|
||||
'offset_number',
|
||||
),
|
||||
'computed_minimum' => array(
|
||||
'product',
|
||||
@ -406,6 +546,25 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends offset to the WP_Query that retrieves Products.
|
||||
*
|
||||
* @since 4.14.0
|
||||
*
|
||||
* @param array $query_args Query args.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function append_offset( $query_args ) {
|
||||
if ( ! is_array( $query_args ) ) {
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
$query_args['offset'] = self::$offset;
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -433,10 +592,11 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
*/
|
||||
public static function get_upsells( $args = array(), $conditional_tags = array(), $current_page = array() ) {
|
||||
self::$static_props = $args;
|
||||
$offset_number = et_()->array_get( $args, 'offset_number', 0 );
|
||||
|
||||
// Force set product's class to ET_Theme_Builder_Woocommerce_Product_Variable_Placeholder
|
||||
// in TB so related product can outputs visible content based on pre-filled value in TB
|
||||
if ( 'true' === et_()->array_get( $conditional_tags, 'is_tb', false ) ) {
|
||||
if ( 'true' === et_()->array_get( $conditional_tags, 'is_tb', false ) || is_et_pb_preview() ) {
|
||||
// Set upsells id; adjust it with module's arguments. This is specifically needed if
|
||||
// the module fetched the value via computed callback due to some fields no longer uses
|
||||
// default value
|
||||
@ -449,6 +609,16 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
add_filter( 'woocommerce_product_class', 'et_theme_builder_wc_product_class' );
|
||||
}
|
||||
|
||||
$is_offset_valid = absint( $offset_number ) > 0;
|
||||
if ( $is_offset_valid ) {
|
||||
self::$offset = $offset_number;
|
||||
|
||||
add_filter(
|
||||
'woocommerce_shortcode_products_query',
|
||||
array( 'ET_Builder_Module_Woocommerce_Upsells', 'append_offset' )
|
||||
);
|
||||
}
|
||||
|
||||
add_filter(
|
||||
'woocommerce_upsell_display_args',
|
||||
array(
|
||||
@ -474,12 +644,18 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
|
||||
remove_filter(
|
||||
'woocommerce_upsell_display_args',
|
||||
array(
|
||||
'ET_Builder_Module_Woocommerce_Upsells',
|
||||
'set_upsell_display_args',
|
||||
)
|
||||
array( 'ET_Builder_Module_Woocommerce_Upsells', 'set_upsell_display_args' )
|
||||
);
|
||||
|
||||
if ( $is_offset_valid ) {
|
||||
remove_filter(
|
||||
'woocommerce_shortcode_products_query',
|
||||
array( 'ET_Builder_Module_Woocommerce_Upsells', 'append_offset' )
|
||||
);
|
||||
|
||||
self::$offset = 0;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
@ -538,6 +714,51 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
return $selected_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Multi view attributes to the Outer wrapper.
|
||||
*
|
||||
* Since we do not have control over the WooCommerce Related Products markup, we inject Multi
|
||||
* view attributes on to the Outer wrapper.
|
||||
*
|
||||
* @param array $outer_wrapper_attrs Outer wrapper attributes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function add_multi_view_attrs( $outer_wrapper_attrs ) {
|
||||
$multi_view = et_pb_multi_view_options( $this );
|
||||
|
||||
$multi_view_attrs = $multi_view->render_attrs(
|
||||
array(
|
||||
'classes' => array(
|
||||
'et_pb_wc_upsells_no_name' => array(
|
||||
'show_name' => 'off',
|
||||
),
|
||||
'et_pb_wc_upsells_no_image' => array(
|
||||
'show_image' => 'off',
|
||||
),
|
||||
'et_pb_wc_upsells_no_price' => array(
|
||||
'show_price' => 'off',
|
||||
),
|
||||
'et_pb_wc_upsells_no_rating' => array(
|
||||
'show_rating' => 'off',
|
||||
),
|
||||
'et_pb_wc_upsells_no_sale_badge' => array(
|
||||
'show_sale_badge' => 'off',
|
||||
),
|
||||
),
|
||||
),
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
if ( $multi_view_attrs && is_array( $multi_view_attrs ) ) {
|
||||
$outer_wrapper_attrs = array_merge( $outer_wrapper_attrs, $multi_view_attrs );
|
||||
}
|
||||
|
||||
return $outer_wrapper_attrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the module output.
|
||||
*
|
||||
@ -668,6 +889,14 @@ class ET_Builder_Module_Woocommerce_Upsells extends ET_Builder_Module {
|
||||
2
|
||||
);
|
||||
|
||||
add_filter(
|
||||
"et_builder_module_{$render_slug}_outer_wrapper_attrs",
|
||||
array(
|
||||
$this,
|
||||
'add_multi_view_attrs',
|
||||
)
|
||||
);
|
||||
|
||||
$output = $this->_render_module_wrapper( $output, $render_slug );
|
||||
|
||||
remove_filter(
|
||||
|
Reference in New Issue
Block a user