Inject Products

You can inject a products into the product loop that’s displayed by the Availability Search for WooCommerce Bookings.

Pre availability checks

You can inject products ids manually to go through the availability checks. If the products are indeed available for the choosen dates then they will be displayed in the product loop.

Adding products here will bypass the categories/taxonomies selection. They products will display fi they pass the availability checks and keyword filter.

/**
 * Inject product ids to be checked for availability and displayed in the loop.
 *
 * Requires ASWB v1.9
 *
 * @param array $product_ids array of product objects.
 * @return array $product_ids to be displayed in the loop.
 */
function custom_inject_product_ids_to_check( $product_ids ) {

	array_unshift( $product_ids, 1973 );

	return $product_ids;
}
add_filter( 'aswb_request_product_ids_for_availability_check', 'custom_inject_product_ids_to_check', 10, 1 );Code language: PHP (php)

Post availability checks

Once all product ID’s have been checked for availability you can inject ANY products of your choosing.

Adding products here will make sure they are displayed, no matter what. It’s possible to add any product types.

/**
 * Inject a product to the front of the Availability Search loop.
 *
 * Requires ASWB v1.9
 *
 * @param array $available_products array of product objects.
 * @return array $available_products to be displayed in the loop.
 */
function custom_inject_product_to_aswb_loop( $available_products ) {

	$my_new_product = wc_get_product( 1973 );

	array_unshift( $available_products, $my_new_product );

	return $available_products;
}
add_filter( 'aswb_request_available_products_for_loop', 'custom_inject_product_to_aswb_loop', 10, 1 );Code language: PHP (php)
Was this page helpful?