[Resolved] Recently Viewed Products

Home Forums Support Recently Viewed Products

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1324943
    Ash

    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?

    #1325019
    David
    Staff
    Customer Support

    Hi there,

    can you share a link so i can see what is going on ?

    #1325247
    Ash

    Sorry, done

    #1325261
    Ash

    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']");
       
    }
    #1325348
    Leo
    Staff
    Customer Support
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.