Custom product layout/loop

Developer level documentation. This is an advanced guide to customize the product loop. PHP knowledge is needed for a correct implementation.

So you’d like to display your products in a custom way? The Availability Search for WooCommerce Bookings will use your themes’s product layout by default. Here’s how to customize it!

Starter Add-on plugin to display a custom loop for ASWB

We’ve put together an example plugin which you can find here

We’ve included an easy filter to override the default product display. You Drop it into your child theme functions.php or a custom plugin. Use our aswb_display_products filter just like the example below:

 * Override the Availability Search for WooCommerce bookings product display
 * This example is simple and doesn't include any product details.

function aswb_custom_filter_product_display( $product_id ) {

// Use $product_id to get the product object, then you can access any data you'd like.
$product = wc_get_product( $product_id );

// Anything you and here must be returned, so it can be used for each product. This will display each name of the products

$output = "<h3>$product->get_name()</h3>";

return $output;

add_filter('aswb_display_products','aswb_custom_filter_product_display' );
Code language: PHP (php)

Get product details

Make sure to first call the WooCommerce Product object like so:

$product = wc_get_product( $product_id );Code language: PHP (php)

You can now access any of the product details by using the below functions.

// Get Product ID
 $product->get_id(); (fixes the error: "Notice: id was called 
incorrectly. Product properties should not be accessed directly")

 // Get Product General Info
 get_permalink( $product->get_id() );

 // Get Product Prices

 // Get Product Tax, Shipping & Stock

 // Get Product Dimensions

 // Get Linked Products
 // Get Product Variations
 // Get Product Taxonomies

 // Get Product Downloads

 // Get Product Images
 get_the_post_thumbnail_url( $product->get_id(), 'full' );

 // Get Product Reviews

// Latest updates can be found at language: PHP (php)
Was this page helpful?