The next article in the series on programming WooCommerce theme, I will show you how to display products that are purchased in WooCommerce a lot.
Many products purchased in WooCommerce
A purchase will be charged when the customer orders successfully. This means that when a product is ordered by a customer, it will count that product for 1 purchase, in case the order is canceled or not paid, the product is still counted as 1 purchase.
Let's go a little deeper:
To understand more and easier to code this function we will go to learn the database. The number of purchases of a certain product will be saved in the WooCommerce wp_postmeta and key_value was total_sales (This is located in the database )
On the picture you can see the school meta_value This field has a value of 0 which means it has not been purchased yet, whereas a field with a value other than 0 means has been purchased.
Display products purchased in WooCommerce
As analyzed above on resignation Display products purchased a lot Now that's pretty simple, we just need to get the product there meta_key was total_sales and sort by the value of meta_value. We have the following code:
'product', 'post_status' => 'publish', 'posts_per_page' => 10, 'meta_key' => 'total_sales', 'orderby' => 'meta_value_num' ); ?> in_the_loop = true; ?> have_posts()) : $getposts->the_post(); ?>
The above code I made took 10 products to buy more. I will explain for you to understand
- ‘Post_type’ => ‘product’ take the real product is not an article
- ‘Post_status’ => ‘publish‘Only posted products, products that are pending review or draft are not posted
- ‘Posts_per_page’ => 10 The number of products to take is 10
- ‘Meta_key’ => ‘total_sales’ Only fetch products with postmeta total_sales
- ‘Orderby’ => ‘meta_value_num’ sorted by value of products sold by a lot
And the bottom is just a get post loop in normal wordpress only.
So I have to guide you how to display Buy more products in WooCommerce. Proactively understanding the database and then implementing the functions will help you improve your programming skills.
Cordially greet and to win!
The post Display products purchased in WooCommerce appeared first on Huy Kira's Blog.Read more :
- Things to know about anvil in Minecraft game - Knowledge-sharing blog
- Thủ thuật tô màu hàng cột trong excel
- Advanced Custom Fields Pro v5.8.10 - WordPress Plugin
- Remote Desktop Manager Enterprise 2020 - Remote VPS control software
- Ripple expands its presence in Asia with 3 new partnerships