WordPress Development Asked by Asif Mughal on October 30, 2021
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
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.
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
Answered by Younes.D on October 30, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP