• Resolved rosbiffer

    (@rosbiffer)


    My woocommerce site collects donations for our charity. Is there an easy way (ideally via shortcode) that would allow me to display the total value of all sales/sales for a specific category in the frontend on a page? I’ve searched everywhere but can’t find it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rosbiffer

    (@rosbiffer)

    I’ve added this snippet which works. What would be the easiest way to add a category filter to it?

    // function that runs when shortcode is called
    function report_total_sales() {
    global $wpdb;
        $order_totals = apply_filters( 'woocommerce_reports_sales_overview_order_totals', $wpdb->get_row( "
        SELECT SUM(meta.meta_value) AS total_sales, COUNT(posts.ID) AS total_orders FROM {$wpdb->posts} AS posts
        LEFT JOIN {$wpdb->postmeta} AS meta ON posts.ID = meta.post_id
        WHERE meta.meta_key = '_order_total'
        AND posts.post_type = 'shop_order'
        AND posts.post_status IN ( '" . implode( "','", array( 'wc-completed', 'wc-processing', 'wc-on-hold' ) ) . "' )
        " ) );
        return absint( $order_totals->total_sales);
    } 
    // register shortcode
    add_shortcode('total_sales', 'report_total_sales'); 
    Plugin Support Dani F. a11n

    (@danielinhou)

    Hi there,

    I would recommend that you ask in the Advanced WooCommerce Group on Facebook(https://www.facebook.com/groups/advanced.woocommerce) to see if someone can help you out there.

    Alternatively, we highly recommend contacting one of the services on our Customizations page (https://woocommerce.com/customizations/)

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display total sales on frontend’ is closed to new replies.