Support » Plugin: Custom Product Tabs for WooCommerce » Custom Product Tabs with WooCommerce REST API

  • Resolved bdcitsolutions

    (@bdcitsolutions)


    Hello,

    we’ve tried to use your plugin via the WooCommerce REST API, but it doesn’t work as expected. We’ve tried to add our tabs directly via the meta_data properties:

    if( !empty($prodrs['MARMEXTRATAB1']) ) {
    	$customTabs[] = array(
    		'title' => 'Technische Daten',
    		'content' => $prodrs['MARMEXTRATAB1']
    	);				
    }
    if( !empty($prodrs['MARMEXTRATAB2']) ) {
    	$customTabs[] = array(
    		'title' => 'Abmessungen',
    		'content' => $prodrs['MARMEXTRATAB2']
    	);				
    }
    
    'meta_data' => [
    	[
    		'key' => 'yikes_woo_products_tabs',
    		'value' => $customTabs
    	]			
    ]

    Both tabs are shown in the product admin page, but in the frontend, only the second tab “Abmessungen” is shown. The first one “Technische Daten” is only shown, if we click on “Save Tabs” in the product admin page.

    Can you help?

    Best, Daniel

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

    (@yikesitskevin)

    Hi Daniel,

    Our tabs also include a tab slug. I think the problem is that you are missing a tab slug. WooCommerce may be trying to use the title as the slug and that is breaking only Technische Daten because it’s two words.

    Try updating your snippet to this:

    if( !empty($prodrs['MARMEXTRATAB1']) ) {
    	$customTabs[] = array(
    		'title'   => 'Technische Daten',
                    'id'      => sanitize_title( 'Technische Daten' ),
    		'content' => $prodrs['MARMEXTRATAB1']
    	);				
    }
    if( !empty($prodrs['MARMEXTRATAB2']) ) {
    	$customTabs[] = array(
    		'title'   => 'Abmessungen',
                    'id'      => sanitize_title( 'Abmessungen' ),
    		'content' => $prodrs['MARMEXTRATAB2']
    	);				
    }
    
    'meta_data' => [
    	[
    		'key' => 'yikes_woo_products_tabs',
    		'value' => $customTabs
    	]			
    ]

    Let me know if that works.

    Cheers,
    Kevin.

    bdcitsolutions

    (@bdcitsolutions)

    Wow, thank you so much for your really fast reply!

    The missing slug was the solution, now it works like a charm 🙂

    Thank you!

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Excellent! Glad that’s working. Cool to see you using tabs with the REST API.

    bdcitsolutions

    (@bdcitsolutions)

    Yes, the REST API is a very cool feature and your plugin is very easy and handy.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.