How to insert shortcodes into the single product page
Open please this example product.
- To insert table with the product variables use next code in file functions.php:
add_filter('woocommerce_after_add_to_cart_button', function() { global $product; if (is_object($product) AND $product->is_type('variable')) { echo do_shortcode("[woot_variations per_page=4 columns='thumbnail,pa_size,pa_color,price,add_to_cart']"); } });
Attribute columns is optional here.
- To insert “Heart, Gallery, popup Button” to the single product page use codde and file functions.php:
add_filter('woocommerce_product_meta_end', function() { echo '<br /><br />' . do_shortcode('[woot_favourites_single_btn]'); echo '<br /><br />' . do_shortcode('[woot_gallery]'); echo '<br /><br />' . do_shortcode('[woot_popup_iframe_button popup_page_link='https://demo.products-tables.com/wpform-contact-ask-me/' button_text='Send message to the product manager' popup_title='Popup header title' css_class='woot-btn']'); echo '<br /><br /><br />' . do_shortcode("[woot_single_btn button_text='Extended information' css_class='woot-btn']").'<br />'; });
- Table attachments placed directly on the text editor by shortcode [woot_attachments columns=”title,file,description”]
- Tabs: reviews, additional information, WOOT Cross Sells, WOOT Upsells, WOOT Related modificated and added by the next code in file functions.php:
add_filter('woocommerce_product_tabs', function ($tabs) { $tabs['reviews'] = array( 'title' => __('WOOT Reviews', 'woocommerce'), 'priority' => 49, 'callback' => function() { $product_id = get_the_ID(); echo '<div id="reviews">' . do_shortcode("[woot_reviews id={$product_id}]") . '</div>'; } ); $tabs['additional_information'] = array( 'title' => __('Additional information', 'woocommerce'), 'priority' => 50, 'callback' => function() { $product_id = get_the_ID(); echo do_shortcode("[woot_single id={$product_id} columns='weight,height,width,pa_size,pa_color,gallery']"); } ); $tabs['woot_cross_sells_tab'] = array( 'title' => __('WOOT Cross Sells', 'woocommerce'), 'priority' => 50, 'callback' => function() { $product_id = get_the_ID(); echo do_shortcode("[woot_cross_sells id={$product_id}]"); } ); $tabs['woot_upsells_tab'] = array( 'title' => __('WOOT UpSells', 'woocommerce'), 'priority' => 50, 'callback' => function() { $product_id = get_the_ID(); echo do_shortcode("[woot_upsells id={$product_id}]"); } ); /* $tabs['woot_grouped_tab'] = array( 'title' => __('WOOT Grouped', 'woocommerce'), 'priority' => 50, 'callback' => function() { $product_id = get_the_ID(); echo do_shortcode("[woot_grouped id={$product_id}]"); } ); */ $tabs['woot_related_tab'] = array( 'title' => __('WOOT Related', 'woocommerce'), 'priority' => 50, 'callback' => function() { $product_id = get_the_ID(); echo do_shortcode("[woot_related id={$product_id}]"); } ); return $tabs; });
Read also: