Bootstrap Templates Bundle

Tuesday, February 3, 2015

Display the number of Products Sold in WooCommerce

//To display the number of units sold for a product, add the following snippet of code to your theme’s functions.php file

<?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>';
}
?>

//or Where You want to show

<?php echo get_post_meta($post->ID, 'total_sales', true); ?> 



No comments:

Post a Comment

Murphy - Home Maintenance & Repair Service HTML Template

Murphy is a handyman repair service Bootstrap HTML Template. It is ideal for either all-rounders or professional teams to introduce the...