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!