• Greetings! I suspect this plugin will be perfect for my client needs. Currently the custom tabs do not show on my product pages however I suspect it’s because I’m using a theme that already has its own tabs.

    I really want to insert the custom tab within the product description. Can you guide me with some code? Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @agrohippy,

    I’m not quite sure what you’re looking for so if I misunderstood you please clarify.

    A few people recently asked for a shortcode to use with Custom Product Tabs. This is not part of the plugin but we developed one that folks can use. Add this code to your site (let me know if you need assistance with that) and then use [custom_product_tabs] within your description. By default, it will show all of our YIKES Custom Product Tabs with no real layout. However, this might be what you’re looking for.

    function yikes_custom_product_tabs_shortcode( $args ) {
    	global $post;
    	
    	// Define our default values
    	$defaults = array(
    		'product_id' => $post->ID,
    		'tab_number' => 'all',
    	);
    
    	// 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 = 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 ) {
    		$html .= '<p>' . $tab['title'] . '</p>';
    		$html .= '<p>' . $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' );

    Let me know.

    Cheers,
    Kevin.

    Thread Starter Erika Jones-Clary

    (@agrohippy)

    This was perfect thank you. I was able to echo the shortcode so I could add the tab information within my product description. Appreciate the quick reply.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Awesome! I’m glad that worked for you.

    Cheers,
    Kevin.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Code to add within description’ is closed to new replies.