<\/div>+/', $shop );
if ( $is_shop_empty || et_()->starts_with( $shop, $shortcode ) ) {
$shop = self::get_no_results_template();
}
return $shop;
}
/**
* Set correct default value for the orderby menu depending on module settings.
*
* @param string $default_orderby default orderby value from woocommerce settings.
* @return string updated orderby value for current module
*/
public function set_default_orderby( $default_orderby ) {
$orderby = $this->props['orderby'];
if ( '' === $orderby || 'default' === $orderby ) {
return $default_orderby;
}
// Should check this explicitly since it's the only option which supports '-desc' suffix.
if ( 'price-desc' === $orderby ) {
return 'price-desc';
}
// Remove '-desc' suffix from other options where Divi may add it.
$orderby = str_replace( '-desc', '', $orderby );
return $orderby;
}
/**
* Get shop HTML for shop module
*
* @param array $args arguments that affect shop output.
* @param array $conditional_tags passed conditional tag for update process.
* @param array $current_page passed current page params.
* @return string HTML markup for shop module
*/
public static function get_shop_html( $args = array(), $conditional_tags = array(), $current_page = array() ) {
$shop = new self();
do_action( 'et_pb_get_shop_html_before' );
$shop->props = $args;
// Force product loop to have 'product' class name. It appears that 'product' class disappears.
// when $this->get_shop() is being called for update / from admin-ajax.php.
add_filter( 'post_class', array( $shop, 'add_product_class_name' ) );
// Get product HTML.
$output = $shop->get_shop( array(), array(), $current_page );
// Remove 'product' class addition to product loop's post class.
remove_filter( 'post_class', array( $shop, 'add_product_class_name' ) );
do_action( 'et_pb_get_shop_html_after' );
return $output;
}
/**
* WooCommerce changed the title tag from h3 to h2 in 3.0.0
*
* @return string HTML markup for title selector.
*/
public function get_title_selector() {
$title_selector = 'li.product h3';
if ( class_exists( 'WooCommerce' ) ) {
global $woocommerce;
if ( version_compare( $woocommerce->version, '3.0.0', '>=' ) ) {
$title_selector = 'li.product h2';
}
}
return $title_selector;
}
/**
* Renders the module output.
*
* @param array $attrs List of attributes.
* @param string $content Content being processed.
* @param string $render_slug Slug of module that is used for rendering output.
*
* @return string
*/
public function render( $attrs, $content, $render_slug ) {
$sticky = et_pb_sticky_options();
$type = $this->props['type'];
$include_categories = $this->props['include_categories'];
$posts_number = $this->props['posts_number'];
$orderby = $this->props['orderby'];
$columns = $this->props['columns_number'];
$multi_view = et_pb_multi_view_options( $this );
$video_background = $this->video_background();
$parallax_image_background = $this->get_parallax_image_background();
$hover_icon = $this->props['hover_icon'];
$hover_icon_values = et_pb_responsive_options()->get_property_values( $this->props, 'hover_icon' );
$hover_icon_tablet = isset( $hover_icon_values['tablet'] ) ? $hover_icon_values['tablet'] : '';
$hover_icon_phone = isset( $hover_icon_values['phone'] ) ? $hover_icon_values['phone'] : '';
$hover_icon_sticky = $sticky->get_value( 'hover_icon', $this->props );
$pagination_display = array();
$pagination_values = et_pb_responsive_options()->get_property_values( $this->props, 'show_pagination' );
$pagination_desktop = et_()->array_get( $pagination_values, 'desktop', '' );
$pagination_tablet = et_()->array_get( $pagination_values, 'tablet', '' );
$pagination_phone = et_()->array_get( $pagination_values, 'phone', '' );
$pagination = in_array( 'off', array( $pagination_tablet, $pagination_phone ), true );
$pagination_display['desktop'] = 'on' === $pagination_desktop ? 'block' : 'none';
$pagination_display['tablet'] = 'on' === $pagination_tablet ? 'block' : 'none';
$pagination_display['phone'] = 'on' === $pagination_phone ? 'block' : 'none';
// only run if mobile device pagination is disabled.
if ( $pagination ) {
et_pb_responsive_options()->generate_responsive_css( $pagination_display, $this->main_css_element . ' nav.woocommerce-pagination', 'display', $render_slug, '', 'yes_no_button' );
}
// Sale Badge Color.
$this->generate_styles(
array(
'base_attr_name' => 'sale_badge_color',
'selector' => '%%order_class%% span.onsale',
'css_property' => 'background-color',
'important' => true,
'render_slug' => $render_slug,
'type' => 'color',
)
);
// Icon Hover Color.
$this->generate_styles(
array(
'hover' => false,
'base_attr_name' => 'icon_hover_color',
'selector' => '%%order_class%% .et_overlay:before',
'css_property' => 'color',
'important' => true,
'render_slug' => $render_slug,
'type' => 'color',
)
);
// Hover Overlay Color.
$this->generate_styles(
array(
'hover' => false,
'base_attr_name' => 'hover_overlay_color',
'selector' => '%%order_class%% .et_overlay',
'css_property' => array( 'background-color', 'border-color' ),
'important' => true,
'render_slug' => $render_slug,
'type' => 'color',
)
);
// Images: Add CSS Filters and Mix Blend Mode rules (if set).
if ( array_key_exists( 'image', $this->advanced_fields ) && array_key_exists( 'css', $this->advanced_fields['image'] ) ) {
$this->add_classname(
$this->generate_css_filters(
$render_slug,
'child_',
self::$data_utils->array_get( $this->advanced_fields['image']['css'], 'main', '%%order_class%%' )
)
);
}
$overlay_attributes = ET_Builder_Module_Helper_Overlay::render_attributes(
array(
'icon' => $hover_icon,
'icon_tablet' => $hover_icon_tablet,
'icon_phone' => $hover_icon_phone,
'icon_sticky' => $hover_icon_sticky,
)
);
// Overlay Icon Styles.
$this->generate_styles(
array(
'hover' => false,
'utility_arg' => 'icon_font_family',
'render_slug' => $render_slug,
'base_attr_name' => 'hover_icon',
'important' => true,
'selector' => '%%order_class%% .et_overlay:before',
'processor' => array(
'ET_Builder_Module_Helper_Style_Processor',
'process_extended_icon',
),
)
);
if ( class_exists( 'ET_Builder_Module_Helper_Woocommerce_Modules' ) ) {
ET_Builder_Module_Helper_Woocommerce_Modules::add_star_rating_style(
$render_slug,
$this->props,
'%%order_class%% ul.products li.product .star-rating',
'%%order_class%% ul.products li.product:hover .star-rating'
);
}
// Module classnames.
$this->add_classname(
array(
$this->get_text_orientation_classname(),
)
);
if ( 'off' === $multi_view->get_value( 'show_name' ) ) {
$this->add_classname( 'et_pb_shop_no_name' );
}
if ( 'off' === $multi_view->get_value( 'show_image' ) ) {
$this->add_classname( 'et_pb_shop_no_image' );
}
if ( 'off' === $multi_view->get_value( 'show_price' ) ) {
$this->add_classname( 'et_pb_shop_no_price' );
}
if ( 'off' === $multi_view->get_value( 'show_rating' ) ) {
$this->add_classname( 'et_pb_shop_no_rating' );
}
if ( 'off' === $multi_view->get_value( 'show_sale_badge' ) ) {
$this->add_classname( 'et_pb_shop_no_sale_badge' );
}
if ( '0' === $columns ) {
$this->add_classname( 'et_pb_shop_grid' );
}
$multi_view_data_attr = $multi_view->render_attrs(
array(
'classes' => array(
'et_pb_shop_no_name' => array(
'show_name' => 'off',
),
'et_pb_shop_no_image' => array(
'show_image' => 'off',
),
'et_pb_shop_no_price' => array(
'show_price' => 'off',
),
'et_pb_shop_no_rating' => array(
'show_rating' => 'off',
),
'et_pb_shop_no_sale_badge' => array(
'show_sale_badge' => 'off',
),
),
)
);
$shop_order = self::_get_index( array( self::INDEX_MODULE_ORDER, $render_slug ) );
$output = sprintf(
'
%5$s
%4$s
%9$s
%10$s
%1$s
',
/* 1$s */ $this->get_shop( array(), array(), array( 'id' => $this->get_the_ID() ) ),
/* 2$s */ $this->module_id(),
/* 3$s */ $this->module_classname( $render_slug ),
/* 4$s */ $video_background,
/* 5$s */ $parallax_image_background,
/* 6$s */ et_core_esc_previously( $overlay_attributes ),
/* 7$s */ esc_attr( $shop_order ),
/* 8$s */ $multi_view_data_attr,
/* 9$s */ et_core_esc_previously( $this->background_pattern() ),
/* 10$s */ et_core_esc_previously( $this->background_mask() )
);
return $output;
}
/**
* Filter the products query arguments.
*
* @since 4.0.5
*
* @param array $query_args Query array.
*
* @return array
*/
public function filter_products_query( $query_args ) {
if ( is_search() ) {
$query_args['s'] = get_search_query();
}
if ( function_exists( 'WC' ) ) {
$query_args['meta_query'] = WC()->query->get_meta_query( et_()->array_get( $query_args, 'meta_query', array() ), true );
$query_args['tax_query'] = WC()->query->get_tax_query( et_()->array_get( $query_args, 'tax_query', array() ), true );
// Add fake cache-busting argument as the filtering is actually done in self::apply_woo_widget_filters().
$query_args['nocache'] = microtime( true );
}
return $query_args;
}
/**
* Filter the vendors products query arguments on vendor archive page.
*
* @param array $query_args WP_Query arguments.
*
* @return array
*/
public function filter_vendors_products_query( $query_args ) {
if ( ! class_exists( 'WC_Product_Vendors' ) ) {
return $query_args;
}
if ( defined( 'WC_PRODUCT_VENDORS_TAXONOMY' )
&& is_tax( WC_PRODUCT_VENDORS_TAXONOMY ) ) {
$term_id = get_queried_object_id(); // Vendor id.
$args = array(
'taxonomy' => WC_PRODUCT_VENDORS_TAXONOMY,
'field' => 'id',
'terms' => $term_id,
);
if ( is_array( $query_args['tax_query'] ) ) {
$query_args['tax_query'][] = $args;
} else {
$query_args['tax_query'] = array( $args );
}
}
return $query_args;
}
/**
* Filter the products shortcode query so Woo widget filters apply.
*
* @since 4.0.8
*
* @param WP_Query $query WP QUERY object.
*/
public function apply_woo_widget_filters( $query ) {
global $wp_the_query;
// Trick Woo filters into thinking the products shortcode query is the
// main page query as some widget filters have is_main_query checks.
$wp_the_query = $query;
// Set a flag to track that the main query is falsified.
$wp_the_query->et_pb_shop_query = true;
if ( function_exists( 'WC' ) ) {
add_filter( 'posts_clauses', array( WC()->query, 'price_filter_post_clauses' ), 10, 2 );
}
}
}
if ( et_builder_should_load_all_module_data() ) {
new ET_Builder_Module_Shop();
}