Search code examples
phpwordpresswoocommerceproductwoocommerce-bookings

wc_get_products not returning bookable products


First time trying to use Woocommerce booking to build a page.

I was changing the products to be bookable and they started to disappear from my custom loop using wc_get_products.

Product category, everything else is not changed. It is not getting bookable products.

Can I use another function for getting my bookable products?

I am very stuck, hoping someone can help.

Here is my code:

<ul>
<?php     // Get some random products.

$args = array(
    'category'=> $post->post_name,
    'showposts'=>-1,
    'type'=>'any'
);
$products = wc_get_products( $args );
$firstrow=true;
?>
<?php foreach ( $products as $item_id => $item_obj ) {?>
<?php
     $item_data = $item_obj->get_data();

$class = ($firstrow) ? 'first' : '' ;
     ?>
<?php $url = get_permalink( $item_data['id'] ) ;?>
        <div class="row">
             <a href="<?php echo $url; ?>">
         <div class="link">
        <div class="floatleft">  
        <div class="plane fontcolor relative"> <img src="<?php echo get_template_directory_uri()?>/images/lennuk.svg">
        </div>
        <div class="inlineblock date <?php echo $class ?>">
         <?php  

          echo $item_obj->get_attribute( 'pa_ajavahemik' );?> 
         </div>

        </div>
       <div class="headtitle floatleft"><?php  echo $item_data['name']?> 
       </div>
       <div class="floatright buttonround">
         <img src="<?php echo get_template_directory_uri()?>/images/vali_viimase_reis.svg">
       </div>
       <div class="floatright tripprice green">
         <?php echo $item_data['regular_price'].' €';?><span class="sale"><?php echo $item_data['sale_price']; ?></span>
       </div>
        <div class="floatright duration">
          <?php 
         echo $item_obj->get_attribute( 'pa_kestus' );?>
       </div>

<div class="clear"></div>

         </div>

         </a>
        </div>
       <?php
           $firstrow=false;
  }
?>
</ul>

Solution

  • I added added 'type' =>'booking' in the $args and it just worked for me.