
}
function woo_get_featured_product_ids() {
/*// Load from cache
$featured_product_ids = get_transient( 'wc_featured_products' );
// Valid cache found
if ( false !== $featured_product_ids )
return $featured_product_ids;*/
$featured = get_posts( array(
'post_type' => array( 'product', 'product_variation' ),
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_visibility',
'value' => array('catalog', 'visible'),
'compare' => 'IN'
),
array(
'key' => '_featured',
'value' => 'yes'
)
),
'fields' => 'id=>parent'
) );
$product_ids = array_keys( $featured );
$parent_ids = array_values( $featured );
$featured_product_ids = array_unique( array_merge( $product_ids, $parent_ids ) );
//set_transient( 'wc_featured_products', $featured_product_ids );
return $featured_product_ids;
}
function sale_products_banner() {
global $woocommerce;
$meta_query = array();
$meta_query[] = $woocommerce->query->visibility_meta_query();
$meta_query[] = $woocommerce->query->stock_status_meta_query();
$meta_query = array_filter( $meta_query );
$product_ids_on_sale = woocommerce_get_product_ids_on_sale();
$featured_ids = woo_get_featured_product_ids();
$args = array(
'posts_per_page'=> 4,
'orderby' => 'rand',
'order' => 'asc',
'no_found_rows' => 1,
'post_status' => 'publish',
'post_type' => 'product',
'meta_query' => $meta_query,
'post__in' => array_merge( array( 0 ), $product_ids_on_sale, $featured_ids )
);
$products = new WP_Query( $args );
if ( count($products->posts) >= 4 ) { ?>