I am using a snippet to show how many items sold for the product in the frontend which displays perfectly.
add_action( 'woocommerce_single_product_summary', 'wp_product_sold_count', 11 );
function wp_product_sold_count() {
global $product;
$total_sold = get_post_meta( $product->id, 'total_sales', true );
if ( $total_sold ) echo '
' . sprintf( __( 'Sold', 'woocommerce' ), $total_sold ) . '
';
}
Now what am trying to show in the product page is, how many items were sold in the past x days.
Is there any snippet that I can use to do so?
Thanks
2
Answers
So I was able to do this via ChatGPT and I got it to work. So here is the final code that worked for me:
This article can help you. Count the number of sold products in the last X days in #woocommerce