Adding a special product attribute to the [products] shortcode.
-
I want to have a products page that shows the customer the items they buy the most. We are a wholesaler and most customers reorder the same items and frequently ask for a list of their best sellers. This sales data does not come from woocommerce orders because most orders are placed ‘offline’ over the phone or in or showroom.
My idea is to load a transient with an array of skus (from a webservice on our Sql Server database) when they log in. This part I know how to do.
What I need help with is how to get the [products] shortcode to use that transient sku array. How would I add a new attribute filter to the short code so that instead of…
[products best_selling="true"]
I could have…
[products customers_best_selling="true"]
That would use a query like
$query_args = array( 'posts_per_page' => $number, 'no_found_rows' => 1, 'post_status' => 'publish', 'post_type' => 'product', 'post__in' => $customers_best_selling, 'orderby' => 'post__in', );
Is it also important that the orderby be ‘post__in’ so that they see their bestsellers fist, instead of the default sort options of post_date/bestselling/price etc.
Also if you think there is a better way to approach this, please let me know.
- The topic ‘Adding a special product attribute to the [products] shortcode.’ is closed to new replies.