Last active
October 13, 2015 08:55
-
-
Save bizzthemes/ebde331cb3061ea82d7c to your computer and use it in GitHub Desktop.
Move appointment booking form to separate tab
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 | |
//* Do NOT include the opening php tag, only copy the code below to functions.php file | |
//* Remove scheduling form | |
add_action( 'wp_head', 'bizzwoo_remove_appointment_form', 0 ); | |
function bizzwoo_remove_appointment_form() { | |
global $wc_appointment_cart_manager; | |
remove_action( 'woocommerce_appointment_add_to_cart', array( $wc_appointment_cart_manager, 'add_to_cart' ), 30 ); | |
} | |
//* Register new tab | |
add_filter( 'woocommerce_product_tabs', 'bizzwoo_new_product_booking_tab' ); | |
function bizzwoo_new_product_booking_tab( $tabs ) { | |
if ( is_product() ) { | |
$product = get_product( get_the_ID() ); | |
if ( $product->is_type( 'appointment' ) ) { | |
// Adds the new tab | |
$tabs['test_tab'] = array( | |
'title' => __( 'Booking', 'woocommerce' ), | |
'priority' => 50, | |
'callback' => 'bizzwoo_new_product_booking_tab_content' | |
); | |
} | |
} | |
return $tabs; | |
} | |
//* New tab content | |
function bizzwoo_new_product_booking_tab_content() { | |
global $product; | |
// Prepare form | |
$appointment_form = new WC_Appointment_Form( $product ); | |
// Get template | |
wc_get_template( 'single-product/add-to-cart/appointment.php', array( 'appointment_form' => $appointment_form ), 'woocommerce-appointments', WC_APPOINTMENTS_TEMPLATE_PATH ); | |
} | |
//* Remove the description tab | |
add_filter( 'woocommerce_product_tabs', 'bizzwoo_remove_product_tabs', 98 ); | |
function bizzwoo_remove_product_tabs( $tabs ) { | |
if ( is_product() ) { | |
$product = get_product( get_the_ID() ); | |
if ( $product->is_type( 'appointment' ) ) { | |
unset( $tabs['description'] ); | |
} | |
} | |
return $tabs; | |
} | |
//* Add the description instead of scheduling form | |
add_action( 'woocommerce_appointment_add_to_cart', 'bizzwoo_description_insteadof_form' ); | |
function bizzwoo_description_insteadof_form() { | |
if ( is_product() ) { | |
$product = get_product( get_the_ID() ); | |
if ( $product->is_type( 'appointment' ) ) { | |
the_content(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment