Stock Progress Bar wrong numbers
-
See image:
https://gyazo.com/85555c73756e2d363db8993d81bf086d
The initial stock is 10 items not 10.0000
How ot fix this?
Hello,
I have viewed other products and progress bar works well. Please provide product URL with the problem
Best Regards
Could you please send us your FTP access so we can check what is wrong with that number?
Try to add the following PHP code snippet to the child theme functions.php file to fix this
function woodmart_stock_progress_bar() { // phpcs:ignore
$product_id = get_the_ID();
$total_stock = get_post_meta( $product_id, 'woodmart_total_stock_quantity', true );
if ( ! $total_stock ) {
return;
}
$current_stock = round( get_post_meta( $product_id, '_stock', true ) );
$total_sold = $total_stock > $current_stock ? $total_stock - $current_stock : 0;
$percentage = $total_sold > 0 ? round( $total_sold / $total_stock * 100 ) : 0;
if ( $current_stock > 0 ) {
echo '<div class="woodmart-stock-progress-bar">';
echo '<div class="stock-info">';
echo '<div class="total-sold">' . esc_html__( 'Ordered:', 'woodmart' ) . '<span>' . esc_html( $total_sold ) . '</span></div>';
echo '<div class="current-stock">' . esc_html__( 'Items available:', 'woodmart' ) . '<span>' . esc_html( $current_stock ) . '</span></div>';
echo '</div>';
echo '<div class="progress-area" title="' . esc_html__( 'Sold', 'woodmart' ) . ' ' . esc_attr( $percentage ) . '%">';
echo '<div class="progress-bar"style="width:' . esc_attr( $percentage ) . '%;"></div>';
echo '</div>';
echo '</div>';
}
}
Worked.
Thank you very much