Title: Shortcodes
Last modified: July 3, 2019

---

# Shortcodes

 *  Resolved [mikosworld](https://wordpress.org/support/users/mikosworld/)
 * (@mikosworld)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/)
 * Hi,
 * In first, congratulation for this awesome plugin for WooCommerce!
 * However I meet a small problem, here, I just installed a builder page (WPBakery
   Visual Composer included in my theme) allowing me to customize my pages (shop
   and products) in WooCommerce. The problem is that there is no possibility to 
   load the tabs stored in each of the products …
    Could you create a function, 
   like shortcode that would import the 2 types of content, by example in this kind:
    - [customprodtabs tabindex=0 content=tabtitle]
    - [customprodtabs tabindex=0 content=tabcontent]
 * In this example, we would load the title of the tab indexed (I guess) as number
   0 of the product currently displayed, finally we would load the text content 
   of the tab number 0 also.
 * Thus, with the pages builders, it would be enough to install an element of the
   type raw text or raw HTML elements and to place these two kinds of shortcodes.
 * Thank you for this great plugin,
    cordially

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696635)
 * Hi [@mikosworld](https://wordpress.org/support/users/mikosworld/),
 * Are you sure there’s no option to load tabs? We have a lot of plugin users who
   also use Visual Composer – this plugin is definitely compatible.
 * Regardless, we do have some custom code you can add to render our product tabs
   as a shortcode. This is the shortcode function:
 *     ```
       function yikes_custom_product_tabs_shortcode( $args ) {
       	global $post;
   
       	// Define our default values
       	$defaults = array(
       		'product_id' => $post->ID,
       		'tab_number' => 'all',
       		'tab_title'  => false,
       	);
   
       	// Let the user-defined values override our defaults
       	$values = is_array( $args ) ? array_merge( $defaults, $args ) : $defaults;
   
       	// Make sure we have a product ID and that the product ID is for a product 
       	if ( empty( $values['product_id'] ) || ! empty( $values['product_id'] ) && get_post_type( $values['product_id'] ) !== 'product' ) {
       		return;
       	}
   
       	// Fetch our tabs
       	$tabs = maybe_unserialize( get_post_meta( $values['product_id'], 'yikes_woo_products_tabs', true ) );
   
       	// Get just the specified tab. (minus tab number by one so it starts at 0)
       	$tabs = absint( $values['tab_number'] ) < 1 ? $tabs : ( isset( $tabs[ absint( $values['tab_number'] ) - 1 ] ) ? array( $tabs[ absint( $values['tab_number'] ) - 1 ] ) : array() );
   
       	if ( empty( $tabs ) ) {
       		return;
       	}
   
       	// Debug statement to show all tab data. Feel free to remove.
       	// echo '<pre>'; var_dump( $tabs ); echo '</pre>';
   
       	$html = '';
   
       	// Loop through the tabs and display each one
       	foreach( $tabs as $tab ) {
   
       		// Check if we're looking for a specific tab title.
       		if ( false !== $values['tab_title'] && strtolower( $tab['title'] ) !== strtolower( $values['tab_title'] ) ) {
       			continue;
       		}
   
       		$html .= '<p>' . $tab['title'] . '</p>';
       		$html .= '<p>' . apply_filters( 'the_content', $tab['content'] ) . '</p>';
       	}
   
       	// Make sure to return your content, do not echo it.
       	return $html;
       }
   
       add_shortcode( 'custom_product_tabs', 'yikes_custom_product_tabs_shortcode' );
       ```
   
 * You can use this shortcode like this:
 * `[custom_product_tabs product_id="" tab_number="" tab_title=""]`
    - `product_id` : the ID of the product you want to show the tabs from. If no
      ID is passed in, we automatically grab the “current” product
    - `tab_number` : this is the number of tabs to display. By default, all of a
      product’s tabs are shown.
    - `tab_title` : this is the title of a specific tab you want to display. For
      example, ‘shipping’ (make sure the tab title is all lowercase)
 * Cheers,
    Kevin.
    -  This reply was modified 6 years, 11 months ago by [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/).
 *  Thread Starter [mikosworld](https://wordpress.org/support/users/mikosworld/)
 * (@mikosworld)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696752)
 * Thank you Kevin for you reply, it works and I confirm in my side there is no 
   element allows to place a custom product field easily… your snippet is welcome
   then!
    Cheers, Nico.
 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696755)
 * Woot! Let me know if you need any improvements to that shortcode. I can see a
   lot of potential updates to it (changing HTML, removing tab title, etc.)
 *  Thread Starter [mikosworld](https://wordpress.org/support/users/mikosworld/)
 * (@mikosworld)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696792)
 * In the plugin itself you could show the ID of the tab in Woocommerce (Custom 
   Tab) section, easier to spot 🙂
    Integrate the functionality you have posted 
   in the plugin itself too, and display a dedicated page where all the parameters
   will be listed for display and copying in the plain text editor/raw HTML as shortcode…
   it’ll work perfectly with all page builders even limited 🙂 Cheers
    -  This reply was modified 6 years, 11 months ago by [mikosworld](https://wordpress.org/support/users/mikosworld/).
 *  Thread Starter [mikosworld](https://wordpress.org/support/users/mikosworld/)
 * (@mikosworld)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696803)
 * And maybe put a shortcode generator according to the desired options, a shortcode
   will be generated, ready to use 😉

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Shortcodes’ is closed to new replies.

 * ![](https://ps.w.org/yikes-inc-easy-custom-woocommerce-product-tabs/assets/icon-
   256x256.png?rev=1558461)
 * [Custom Product Tabs for WooCommerce](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yikes-inc-easy-custom-woocommerce-product-tabs/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/)
 * [Active Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yikes-inc-easy-custom-woocommerce-product-tabs/reviews/)

## Tags

 * [feature](https://wordpress.org/support/topic-tag/feature/)
 * [including](https://wordpress.org/support/topic-tag/including/)
 * [integration](https://wordpress.org/support/topic-tag/integration/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)
 * [woo](https://wordpress.org/support/topic-tag/woo/)

 * 5 replies
 * 2 participants
 * Last reply from: [mikosworld](https://wordpress.org/support/users/mikosworld/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/shortcodes-335/#post-11696803)
 * Status: resolved