• Resolved Juraj Hamara

    (@jurajj)


    Hello,
    I have following code that adds a simple notice about stock availability and shipping into product on shop/archive page, but in case when product stock quantity is 0 (is out of stock) notice is not showing up. Can someone help? Thanks a lot.

    add_action( 'woocommerce_after_shop_loop_item','show_stock_shop', 90 );
    
    function show_stock_shop() {
        global $product;
    
        $regular = $product->regular_price;
        $sale = $product->sale_price;
    //  $stock = the_field('stock-available');
    
        if ( $product->stock ) { // if manage stock is enabled 
            if ( $product->get_stock_quantity() > 0 && $regular >= 500 || $sale >= 500  ) { // in stock, free shipping
                echo '<div class="remaining text-center pt-2 pb-2">Skladom. <span class="doprava-zadarmo">Doprava zadarmo</span></div>';
            } elseif ( $product->get_stock_quantity() == 0 && $regular >= 500 || $sale >= 500 ) { // out of stock, free shipping
                echo '<div class="remaining text-center pt-2 pb-2"><s>(nie je skladom)</s>. <span class="doprava-zadarmo">Doprava zadarmo</span></div>';
            } elseif ( $product->get_stock_quantity() > 0 && $regular < 500 || $sale < 500 ) { // in stock, not free shipping
                echo '<div class="remaining text-center pt-2 pb-2">Skladom. <span class="doprava-zadarmo">Doprava zadarmo od 500 eur</span></div>';
            } elseif ( $product->get_stock_quantity() == 0 && $regular < 500 || $sale < 500 ) { // out of stock, not free shipping
                echo '<div class="remaining text-center pt-2 pb-2"><s>(nie je skladom)</s>. <span class="doprava-zadarmo">Doprava zadarmo od 500 eur</span></div>';
            } else {
                echo '<div class="remaining text-center pt-2 pb-2">Do ' . /*$stock .*/ ' dní</div>'; 
            }
        }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Soft79

    (@josk79)

    Assuming you’re using WC 3.x:

    Replace

    if ( $product->stock ) {

    By:

    if ( $product->get_manage_stock() ) {

    PS: you also should use the proper get_ functions for sale_price and regular_price.

    • This reply was modified 6 years ago by Soft79. Reason: WC3.x assumption
    Thread Starter Juraj Hamara

    (@jurajj)

    It’s okay. Thank you ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stock availability’ is closed to new replies.