• Resolved martim87

    (@martim87)


    Hi,
    I need an information, there is a plugin or a simple solution to put some information under each product in shop page woocommerce?

    I’d like to insert the stock quantity, the product’s code and a space to enter the quantity imput to order.

    Thanks in advance,
    Martina

Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi, @martim87!

    I’d like to insert the stock quantity

    You can use the following code:

    function show_stock() {
    global $product;
    if ( $product->get_stock_quantity() ) { // if manage stock is enabled 
    if ( number_format($product->get_stock_quantity(),0,'','') < 3 ) { // if stock is low
    echo '<div class="remaining">Only ' . number_format($product->get_stock_quantity(),0,'','') . ' left in stock!</div>';
    } else {
    echo '<div class="remaining">' . number_format($product->get_stock_quantity(),0,'','') . ' left in stock</div>'; 
    		}
    	}
    }
    
    add_action('woocommerce_after_shop_loop_item','show_stock', 10);

    the product’s code

    If you’re referring to the SKU, then use this code:

    function wc_shop_display_skus() {
    
    	global $product;
    	
    	if ( $product->get_sku() ) {
    		echo '<div class="product-meta">SKU: ' . $product->get_sku() . '</div>';
    	}
    }
    add_action( 'woocommerce_after_shop_loop_item', 'wc_shop_display_skus', 11 );

    a space to enter the quantity imput to order

    Here’s how you can add the quantity inputs on shop/archive page:

    https://www.thathandsomebeardedguy.com/add-quantity-inputs-to-simple-products-on-the-woocommerce-shop-page/

    All custom code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as Code Snippets. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

    Cheers!

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Stock quantity, code under each product in the shop woocommerce’ is closed to new replies.