‘5’
), $atts));

// Get WooCommerce Global
global $woocommerce;

// Get recently viewed product cookies data
$viewed_products = ! empty( $_COOKIE[‘woocommerce_recently_viewed’] ) ? (array) explode( ‘|’, $_COOKIE[‘woocommerce_recently_viewed’] ) : array();
$viewed_products = array_filter( array_map( ‘absint’, $viewed_products ) );

// If no data, quit
if ( empty( $viewed_products ) )
return __( ‘You have not viewed any product yet!’, ‘rc_wc_rvp’ );

// Create the object
ob_start();

// Get products per page
if( !isset( $per_page ) ? $number = 5 : $number = $per_page )

// Create query arguments array
$query_args = array(
‘posts_per_page’ => $number,
‘no_found_rows’ => 1,
‘post_status’ => ‘publish’,
‘post_type’ => ‘product’,
‘post__in’ => $viewed_products,
‘orderby’ => ‘rand’
);

// Add meta_query to query args
$query_args[‘meta_query’] = array();

// Check products stock status
$query_args[‘meta_query’][] = $woocommerce->query->stock_status_meta_query();

// Create a new query
$r = new WP_Query($query_args);

// If query return results
if ( $r->have_posts() ) {

$content = ‘

‘;

}

// Get clean object
$content .= ob_get_clean();

// Return whole content
return $content;
}

// Register the shortcode
add_shortcode(“woocommerce_recently_viewed_products”, “rc_woocommerce_recently_viewed_products”);