Archived topic
Recently Viewed Products
4 replies · Started by Ash on June 12, 2020
Trying to get recently view products to work in a hook, can't seem to get it to work.
Added shortcode, execute shortcode, after single product, location all products, but it just showed as text.
Any ideas?
Hi there,
can you share a link so i can see what is going on ?
Sorry, done
Managed to get it to show. Any ideas how I can limit it to only 4.
Using this function
add_shortcode( 'recently_viewed_products', 'bbloomer_recently_viewed_shortcode' );
function bbloomer_recently_viewed_shortcode() {
$viewed_products = ! empty( $_COOKIE['woocommerce_recently_viewed'] ) ? (array) explode( '|', wp_unslash( $_COOKIE['woocommerce_recently_viewed'] ) ) : array();
$viewed_products = array_reverse( array_filter( array_map( 'absint', $viewed_products ) ) );
if ( empty( $viewed_products ) ) return;
$title = '<h3>Recently Viewed Products</h3>';
$product_ids = implode( ",", $viewed_products );
return $title . do_shortcode("[products ids='$product_ids']");
}
That would be a question for WooCommerce support.
Perhaps this would help?
https://stackoverflow.com/questions/47242438/woocommerce-recently-viewed-products