Show Random WooCommerce Products from a Category

A custom WooCommerce extension script, called via a shortcode, to show a list of random products from a category. This script was actually created for a client who uses the Avada theme. The Avada theme overrides most of the WooCommerce product display shortcodes with their own library so it makes certain parameters unavailable.

This script can be added to the theme’s function.php file.

 

The Shortcode Function

Shortcode Example:

We want to display 4x products from the category “20” in 4x columns.

First we would need to create a new shortcode hook that in return referance a callback function called: “woocommerce_custom_category_shortcode”.

Now we can create the function called.: “woocommerce_custom_category_shortcode”.