By default the “out of stock” message is being output as a <p>
tag after the product description. How can I change the location where this message is being rendered?
1 Answer
To override the default “out of stock” message that is being outputted as a <p>
tag, copy:
wp-content/plugins/woocommerce/templates/single-product/add-to-cart/simple.php
to
wp-content/themes/yourtheme/woocommerce/single-product/add-to-cart/simple.php
See edit Woocommerce template files
Open the copied file. On line 17 to 23 you find this code:
<?php
// Availability
$availability = $product->get_availability();
if ($availability['availability']) :
echo apply_filters( 'woocommerce_stock_html', '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>', $availability['availability'] );
endif;
?>
Here you can change the <p>
tag to whatever you want. For example, I edited it to:
<?php
// Availability
$availability = $product->get_availability();
if ($availability['availability']) :
echo apply_filters( 'woocommerce_stock_html', '<div class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</div>', $availability['availability'] );
endif;
?>
So the output was:
<div class="stock out-of-stock">Out of stock</div>
Important links:
- Woocommerce Hooks