WooCommerce Recently Viewed Products Shortcode Plugin

By WP Saviour •  Updated: 01/24/21 •  3 min read

A variety of days previously, WooThemes group launched mannequin 2 of the highly regarded WooCommerce plugin that allows every single WordPress site to advertise any type of merchandise very merely. Even when i’m further used to work with the superior Simple Digital Downloads plugin, by the very gifted Pippin Williamson, i wanted to go a bit deeper into WooCommerce and current you methods it’s essential to use present choices to create new capabilities. And as we communicate i’d wish to make clear you learn to create a shortcode that reveals these days seen merchandise. These days seen merchandise is an especially extremely efficient perform simply because it’s, for me, form of very basic artificial intelligence. It permits prospects to easily return to merchandise they already seen in solely a matter of seconds. you could place it in every single place in your site on account of  using a shortcode to point out these days seen merchandise is good.

Often when i create a tutorial on WPSaviour i make clear step-by-step the technique, nonetheless as as we communicate’s tuto is a bit longer, i favor to make clear the whole course of after which to give you the entire code with suggestions straight into the code.

Doing it inside a shortcode

So, we’re going to create a plugin which will register a [woocommerce_recently_viewed_products per_page=”5″] shortcode. Why making a plugin? On account of it’s the most effective strategy to retailer a perform that it’s essential to use with any theme. Once you resolve to register a shortcode proper right into a theme, the shortcode shall be obtainable offered that the theme is activated. With WooCommerce Merchandise Shortcode Plugin, whatever the theme you’re using, the perform will nonetheless be obtainable. One different essential issue, is that it’s essential to not at all ever modify WooCommerce recordsdata.

Would you like cookies? I really do!

By default WooCommerce creates a cookie that retailers important details about what a buyer does and sees on the shop. And that’s exactly the form of data we’ve to create WooCommerce Merchandise Shortcode Plugin . A really highly effective data we would like are saved proper right into a cookies often known as $_COOKIE[‘woocommerce_recently_viewed’]. Principally this cookie retailers the ID of the lastest seen merchandise. As WooCommerce is already saving these IDs.Our job is to create a fantastic query using the “put up in” query attribute.  And along with be sure that the merchandise we’ve to point out are nonetheless in stock. To take motion, we’ve to make use of the $woocommerce->query->stock_status_meta_query() methodology into the “meta_query” query attribute.

The plugin full code

i added the suggestions straight into the code, as a result of the code is pretty straightforward , and that i didn’t do a step-by-step tutorial, however when one factor isn’t clear please write a comment and that i’ll be greater than happy to make clear you each part of the code!

WP Saviour

I am a WordPress specialist. My mission is to help you create beautiful websites with ease!