Home Forums General Issues Snippet with ACF field and Woocommerce stock


Snippet with ACF field and Woocommerce stock

  • Hi there,

    I’m trying to get this code to work in my functions.php, but I’m missing something where I get the posts I guess.
    Products have a few ACF field, including one called ‘date_of_event’. That’s a datepicker field. I want to hide all products that are out of stock and the date has past. For the products where the stock is 0, but the date in the future I want to display them (don’t hide).
    Can anyone check my code and tell me what I am missing?

    add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'bbloomer_hide_out_of_stock_exception_page' );
    function bbloomer_hide_out_of_stock_exception_page( $hide ) {
    		$sDate = get_field('date_of_event');
    		$currendDate = date('Ymd');
    		if($sDate > $currendDate){
          $hide = 'no';
       return $hide;
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.