I think there is quite an easy solution:
In WooCommerce I want to apply my delivery time filter to a single product, but only if it is available/in stock
. I am getting an error when it comes to any kind of checking the products stock.
function filter_woocommerce_germanized_delivery_time_html( $str_replace, $html ) {
global $product;
if( $product->is_in_stock() ) {
echo '<p class="wc-gzd-additional-info delivery-time-info">';
echo $str_replace;
echo '</p>';
echo '<p class="wc-gzd-additional-info"><a href="https://xyz.at/info/lieferzeiten/" target="_blank"><i class="fas fa-shipping-fast"></i> EU-Lieferzeiten</a></p></span>';
}
}
// add the filter
add_filter( 'woocommerce_germanized_delivery_time_html', 'filter_woocommerce_germanized_delivery_time_html', 10, 2 );
I also tried:
if($product->get_stock_quantity()>0)
But similar errors like:
"Uncaught Error: Call to a member function is_in_stock() on null.."
Thanks for the help!
Regards, Felix