Created
November 10, 2018 16:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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