Display Total Product Sold Quantity to WooCommerce Page

Display Total Product Sold Quantity to WooCommerce Page
103 Views

Currently your customers have no idea how many quantity or downloads have been ordered from your WooCommerce site. So in order to apply this change, you can add below code into your child theme’s functions.php file.

This snippet code show you how to display total product sold quantity WooCommerce page.

get_total_sales();
if ( $units_sold ) echo ‘

‘ . sprintf( __( ‘Units Sold: %s’, ‘woocommerce’ ), $units_sold ) . ‘

‘;
}

/* Display product sold count at shop page */

add_action( ‘woocommerce_after_shop_loop_item’, ‘get_product_sold_count_at_shop’, 9 );

function get_product_sold_count_at_shop() {
global $product;
$sales = $product->get_total_sales();
?>

get_total_sales();
$text = __( “Total Sold:”, “woocommerce” ) . ‘ ‘;

return $cart_item_name . ‘ – ‘ . $text . $sales;
}

/*Display product sold count at order page and email notifications */

add_filter( ‘woocommerce_order_item_name’, ‘add_single_excerpt_to_order_item’, 10, 3 );

function add_single_excerpt_to_order_item( $item_name, $item, $is_visible ){
$product = $item->get_product();
$sales = $product->get_total_sales();
$text = __( “Total Sold:”, “woocommerce” ) . ‘ ‘;

return $item_name . ‘ – ‘ . $text . $sales;
}

/*Display product sold count at admin order edit page */

add_action( ‘woocommerce_before_order_itemmeta’, ‘total_sales_before_order_itemmeta’, 10, 3 );

function total_sales_before_order_itemmeta( $item_id, $item, $product ){
if( ! ( is_admin() && $item->is_type(‘line_item’) ) ) return;

echo ‘

‘ .__( “Total sales” ) . ‘: ‘ . $product->get_total_sales() . ‘

‘;
}
?>

Was this article helpful?
YesNo

Leave a comment

Your email address will not be published.