Using the shortcode in Divi Template Builder

Issue #523 resolved
Valentina R created an issue

I didn’t know that one can do a template page in Divi by using the Visual Builder, but this customer says that it can be done. And because the template is not done in code, there is no way of adding the appointments shortcode in it - because the ID is not defined in the template.

Can this be done? Or does it need some custom implementation or us changing the core?

Asked here: [https://bookingwp.com/forums/topic/custom-divi-product-detail-page-and-shortcode-use/](https://bookingwp.com/forums/topic/custom-divi-product-detail-page-and-shortcode-use/)

Comments (1)

  1. Željan Topić

    Shared this shortcode with the customer:

    add_shortcode( 'product_appointment_form', 'product_appointment_form_shortcode' );
    function product_appointment_form_shortcode() {
        global $product;
    
        // Stop here when $product is not defined.
        if ( ! $product ) {
            return;
        }
    
        ob_start();
    
        // 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,
            ),
            '',
            WC_APPOINTMENTS_TEMPLATE_PATH
        );
    
        return ob_get_clean();
    }
    
  2. Log in to comment