Get WooCommerce Products total sales amount or Net & Gross Revenue

| |

You can use following custom functions that will give you Gross/Net Revenue for each product or to get woocommerce products total sales:

Write this code in your active theme’s function.php

Get WooCommerce Products total sales Net Revenue


function get_product_net_revenue( $product_id ) {
    global $wpdb;

    return (float) $wpdb->get_var( $wpdb->prepare("
        SELECT SUM(product_net_revenue)
        FROM {$wpdb->prefix}wc_order_product_lookup
        WHERE product_id = %d
    ",$product_id ) );
}

Get WooCommerce Products Gross Revenue


function get_product_gross_revenue( $product_id ) {
    global $wpdb;

    return (float) $wpdb->get_var( $wpdb->prepare("
        SELECT SUM(product_gross_revenue)
        FROM {$wpdb->prefix}wc_order_product_lookup
        WHERE product_id = %d
    ",$product_id ) );
}

If you want to use this inside loop use following:

<?php $amount = get_product_net_revenue( $loop->post->ID ); ?>


How to increase WordPress Memory Limit

Next