Hi @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.
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.
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.)
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, 10 months ago by
mikosworld.
And maybe put a shortcode generator according to the desired options, a shortcode will be generated, ready to use 😉