0

I use this solution How to add custom stock status to products in WooCommerce 4+ on my page.

I try to use this custom status on shop page. But on shop page I get only two status in stock and out of stock.

add_filter('woocommerce_get_price_html', 'uni_price', 9999, 2);

function uni_price($price, $product) {

global $product;

// Is a WC product
if (is_a($product, 'WC_Product')) {
    // Get stock status
    $product_stock_status = $product->get_stock_status();
    // Compare
    if ($product_stock_status == 'Coming soon') {
        $price = '<span class="woocommerce-Price-amount amount tbdprice com">Coming soon</span>';
    }
}

return $price;

}

Someone who can assist me with this?

  • Use (temporarily) `echo '

    DEBUG INFOMATION = ' . $product->get_stock_status() . '

    ';` right after `if (is_a($product, 'WC_Product')) {`, then you will see the issue..
    – 7uc1f3r Apr 04 '22 at 12:57
  • Thank You for your answer. I get only two status in stock and out of stock. I use custom "coming soon"? How can i get it? – Krzysztof Pietryga Apr 04 '22 at 13:15
  • I wrote the answer as a comment (and updated the link/my answer you refer to in your question with some examples), look at the outcome. So either the status is not equal to `Coming soon` but for example `coming_soon` or it's a matter of debugging, since `$product->get_stock_status()` works by default with this hook + custom stock status code answer without more. P.s. the use of `global $product;` is redundant, as `$product` is already passed as 2nd argument to the callback function when using this hook – 7uc1f3r Apr 04 '22 at 15:03

0 Answers0