0

I am trying to add order, sale count next to star rating at single product page, my store is built with WordPress and Woocommerce, I have tried a code but it adds this function before add to cart button/form.

Website URL for reference: https://techcart.pk

and image

enter image description here

Code:

add_action( 'woocommerce_before_add_to_cart_button', 'product_sold_count', 10 );
  function product_sold_count() {
   global $product;
   $units_sold = $product->get_total_sales();
   if ( $units_sold ) echo '<p>' . sprintf( __( 'Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';

I will appreciate if anyone helps me in this matter.

1 Answer 1

0

For single product page, I tested it with the themes: ShoppingCart and Storefront and it works fine :

in function.php:

function shoppingcart_setup(){

  add_filter('woocommerce_short_description', function(){
    
     global $product;
     $units_sold = $product->get_total_sales();
     if ( $units_sold ) return '<p>' . sprintf( __( 'Sold: %s', 'woocommerce' ), $units_sold ) . '</p>';             
        
  }, 10, 2);
}
add_action( 'after_setup_theme', 'shoppingcart_setup' );

Note: If you checked: Manage Stock, this code does not work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.