Home Forums WoodMart support forum Stock Progress Bar wrong numbers

Stock Progress Bar wrong numbers

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #94779

    nbento
    Participant

    See image:
    https://gyazo.com/85555c73756e2d363db8993d81bf086d
    The initial stock is 10 items not 10.0000

    How ot fix this?

    #94801

    Hello,

    I have viewed other products and progress bar works well. Please provide product URL with the problem

    Best Regards

    #94821

    nbento
    Participant
    #94841

    nbento
    Participant

    Any word on this?

    #94855

    Artem Temos
    Keymaster

    Could you please send us your FTP access so we can check what is wrong with that number?

    #94944

    nbento
    Participant

    Info requested

    #94952

    Artem Temos
    Keymaster

    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>';
    		}
    	}
    #94998

    nbento
    Participant

    Worked.
    Thank you very much

    #95031

    Artem Temos
    Keymaster

    You are welcome.

Viewing 9 posts - 1 through 9 (of 9 total)