• Resolved mikosworld

    (@mikosworld)


    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

    (@yikesitskevin)

    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.

    • This reply was modified 4 months, 2 weeks ago by yikesitskevin.

    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

    (@yikesitskevin)

    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 4 months, 2 weeks ago by mikosworld.

    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)
  • You must be logged in to reply to this topic.