Created
May 25, 2020 22:35
-
-
Save jackbillstrom/d21e491f2ab878449aaee9c049c304e8 to your computer and use it in GitHub Desktop.
[WooCommerce] Recently Viewed Products
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* goes inside your beloved functions.php | |
*/ | |
add_shortcode( 'recently_viewed_products', 'code_recently_viewed_products' ); | |
function code_recently_viewed_products() { | |
$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>Andra har även tittat på</h3>'; | |
$product_ids = implode( ",", $viewed_products ); | |
return $title . do_shortcode("[products ids='$product_ids']"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment