Allow [products] to be used instead of any other product shortcode

This allow `[products]` to be used instaed of `[product_category]`,
`[featured_products]`, `[sale_products]`, `[best_selling_products]`,
`[recent_products]`, and `[top_rated_products]`.

Ref #15979
This commit is contained in:
Claudio Sanches 2017-08-25 20:04:53 -03:00
parent b6f789fc56
commit 500ee02dfa
1 changed files with 16 additions and 2 deletions

View File

@ -246,7 +246,21 @@ class WC_Shortcodes {
* @return string
*/
public static function products( $atts ) {
$shortcode = new WC_Shortcode_Products( (array) $atts );
$atts = (array) $atts;
$type = 'products';
// Allow list product based on specific cases.
if ( isset( $atts['on_sale'] ) && wc_string_to_bool( $atts['on_sale'] ) ) {
$type = 'sale_products';
} elseif ( isset( $atts['best_selling'] ) && wc_string_to_bool( $atts['best_selling'] ) ) {
$type = 'best_selling_products';
} elseif ( isset( $atts['top_rated'] ) && wc_string_to_bool( $atts['top_rated'] ) ) {
$type = 'top_rated_products';
} elseif ( isset( $atts['featured'] ) && wc_string_to_bool( $atts['featured'] ) ) {
$type = 'featured_products';
}
$shortcode = new WC_Shortcode_Products( $atts, $type );
return $shortcode->get_content();
}
@ -583,7 +597,7 @@ class WC_Shortcodes {
'per_page' => '12',
'columns' => '4',
'orderby' => 'title',
'order' => 'asc',
'order' => 'ASC',
'attribute' => '',
'filter' => '',
), (array) $atts );