WordPress Codesnippets

woocommerce get sale percentage


This code calculates and displays the percentage of sale orders out of total orders. WC() is a WordPress function that grabs the sales statistics from the WordPress database. get_total_sales() and get_total_orders() are used to get the total sales and orders respectively. The sale percentage is calculated by dividing the total sales by the total orders and multiplying the result by 100. Finally, the sale percentage is echoed to the screen.

Was this code snippet helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmatically save post

This code creates a WordPress post with the values of the ‘post_title’ and ‘post_content’ variables. It sets the post status to ‘publish’ and the author

Read More »

Create order programmatically

This code creates a new post in the WordPress database with post type ‘shop_order’, post title ‘Order #12345’, post status ‘wc-processing’, and ping status ‘closed’.

Read More »