Function showing same result count product have left WooCommerce
I want showing products have left / total product and show by the progress bar, on product page work fine, but on loop page (category, shop page) just showing the same result of one product, this should be a different result on a product. Here is the code
jQuery(document).ready(function(){ 'use strict'; var wbpsSale = jQuery('#wpbsc_total_sale').attr('total-sale'); var wbpsStock = jQuery('#wpbsc_total_sale').attr('total-stock'); var jqmeter_params = { goal:wbpsStock, raised:wbpsSale, meterOrientation:'horizontal', displayTotal: true, width:'100%', height:'17px' }; jQuery("corergb-bar").jQMeter(jqmeter_params); });
function wpbsc_show_stock_shop() { global $product; global $post; $manage_stock = get_post_meta( $post->ID, '_manage_stock', true ); if( $product->is_on_sale() && $product && $manage_stock == 'yes'){ $stock = get_post_meta( $post->ID, '_stock', true ); $wpbscSale = $product->get_total_sales(); $wpbscTotalStock = intval($stock)+ intval($wpbscSale); ?> <div class="wpbsc-stock-counter"> <div id="wpbsc_total_sale" class="total-sale-stat" total-sale="<?php echo esc_attr( $wpbscSale ); ?>" total-stock="<?php echo esc_attr($wpbscTotalStock) ?>"></div> <p class="stock-progressbar-status"><span class="total-sold"> <?php echo esc_html__("Đã bán: {$wpbscSale}",'wpbsc'); ?></span></p> <div id="corergb-bar" class="bar-progress-stat"></div> </div> <?php } }
Pls help me, i want showing to hook "woocommerce_after_shop_loop_item_title" with different result on a product
image example:
here is showing on product page
showing on category but only progress bar not with percent
when i change jQuery("[id='corergb-bar']")
to jQuery('.bar-progress-stat')
the result progress bar showing but same result for all product have manage_stock
image example: should be different result on a product