Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Created November 10, 2018 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/028be402d496a99cbc1b1b6e2a4972d3 to your computer and use it in GitHub Desktop.
Save cliffordp/028be402d496a99cbc1b1b6e2a4972d3 to your computer and use it in GitHub Desktop.
Pseudo code for putting the WooCommerce Bookings Form anywhere, such as via a shortcode. READ THE CODE COMMENTS
<?php
/**
* Pseudo code for putting the WooCommerce Bookings Form anywhere, such as via a shortcode.
* !!! READ THE CODE COMMENTS !!!
*
* @link http://ideas.woocommerce.com/forums/133476-woocommerce/suggestions/34526179-creating-shortcode-booking-search-form-with-date-r
*
* @see WC_Booking_Cart_Manager::add_to_cart()
*
* @return string
*/
function your_booking_form_anywhere() {
global $product;
// Add your own logic to confirm this is a bookable product... then...
ob_start();
if ( 'yes' !== get_option( 'woocommerce_cart_redirect_after_add' ) ) {
wc_print_notices();
}
printf( '<div class="%s">', __FUNCTION__ );
if ( $atts['heading'] ) {
printf( '<h2>%s</h2>', $atts['heading'] );
}
wc_get_template( 'single-product/add-to-cart/booking.php', [ 'booking_form' => new WC_Booking_Form( $product ) ], 'woocommerce-bookings', \WC_BOOKINGS_TEMPLATE_PATH );
echo '</div>';
$output = ob_get_clean();
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment