Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seb86/0325d26428d406a3acf8d533a661c38e to your computer and use it in GitHub Desktop.
Save seb86/0325d26428d406a3acf8d533a661c38e 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>';
}
?>
@izakjanse
Copy link

hi how would i go about creating a shortcode as i dont want to apply this to all my pages just some products and i want to be able to ad my own text before and after the number as well place it where ever i feel fit

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