2

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?

closed as off-topic by Rarst Feb 6 '14 at 19:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

4

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:

  1. Woocommerce Hooks
  • 1
    Ravs, the idea is "we collect solutions, not links". This guide will help: How to Answer. – brasofilo May 18 '13 at 16:56
  • 1
    answer edited try it – Ravinder Kumar May 18 '13 at 20:28
  • Great improvement! Please leave the steps from your first draft in your answer. They are useful. – fuxia May 18 '13 at 20:39
  • I updated answer link for woocommerce hooks for more info – Ravinder Kumar May 18 '13 at 20:52
  • @bungeshea thanks for correct me. Next time i'll take care of answers formatting. – Ravinder Kumar May 19 '13 at 6:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.