"Sold X Times" Note on Product Pages
Shows how many times a product has been bought below its price, as social proof once it passes a minimum number of sales.
Opens WPIDE on
Code
add_action( 'woocommerce_single_product_summary', function () {
$min_sales = 10; // Hide the note below this many sales.
global $product;
if ( ! $product instanceof WC_Product ) {
return;
}
$sales = (int) $product->get_total_sales();
if ( $sales < $min_sales ) {
return;
}
echo '<p class="wpide-units-sold" style="margin:.5em 0;font-size:.95em;">' . esc_html( sprintf( 'Bought %s times', number_format_i18n( $sales ) ) ) . '</p>';
}, 11 );
Notes
Set $min_sales so new products do not show a low number.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.