Skip to content

Instantly share code, notes, and snippets.

@kloon
Last active December 9, 2017 14:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kloon/6238672 to your computer and use it in GitHub Desktop.
Save kloon/6238672 to your computer and use it in GitHub Desktop.
WooCommerce display number of products sold on single product page
<?php
add_action( 'woocommerce_single_product_summary', 'wc_product_sold_count', 11 );
function wc_product_sold_count() {
global $product;
$units_sold = get_post_meta( $product->id, 'total_sales', true );
echo '<p>' . sprintf( __( 'Units Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';
}
?>
@kachmul2004
Copy link

i added this code to my funcitons php, but units sold just show 1 on all products. Using the latest woocommerce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment