• Resolved Mike Oberdick

    (@mike_oberdick)


    Got an interesting situation for you guys…I have a client who was using the default WooCommerce tab manager plugin. They used this for all of their products up until about a month ago when I developed some custom solutions for them to upload their products via WP All Import. I set it up using your tabs plugins and WP All Import integration and ran into an issue where the WooCommerce tab plugin is overriding your plugin so the custom tabs aren’t showing for the products which were imported using WP All Import.

    Essentially, the old products use tabs built with the native WooCommerce Tab Manager and all of the new products are using tabs created with your plugin. Any way for them to coexist so that the old products show the WooCommerce Tab Manager tabs and the new products show the tabs created with your plugin?

    The page I need help with: [log in to see the link]

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

    (@yikesitskevin)

    Hi @mike_oberdick,

    I haven’t seen this issue before. Which Tabs Manager plugin is it? The paid one by WooCommerce (https://woocommerce.com/products/woocommerce-tab-manager/)? If it’s something I can easily download and test I will. If it’s not, I am not sure how to resolve this.

    Have you confirmed that disabling the Tabs Manager plugin enables Custom Product Tabs (this plugin’s tabs) to work?

    Let me know.

    Cheers,
    Kevin.

    Thread Starter Mike Oberdick

    (@mike_oberdick)

    Thanks so much Kevin for getting back to me.

    Yes, it’s the paid one that is causing the issue. Is there a direct e-mail where I can send you a link? If I disable the Tabs Manager Plugin then the Custom Product Tabs works fine. I’m thinking it’s an issue with priority for when the filter/hook is run?

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    An issue with priority for the filter is possible. The plugin also claims:

    Even most 3rd party tabs added by other plugins will be detected, allowing you to hide or order them alongside your own tabs.

    So I’m wondering whether that functionality is breaking something.

    Feel free to email plugins at yikesinc dot com!

    Thanks,
    Kevin.

    Thread Starter Mike Oberdick

    (@mike_oberdick)

    Kevin based on what you wrote, I was able to find this on their site:

    If your 3rd party tab relies on the global $product variable, the Tab Manager won’t be able to display the tab within its default settings, which means that the tab disappears :(.

    The basic idea here is that you should add the tab even if $product is undefined so that Tab Manager picks it up. If you want to conditionally show tabs on the product page, you can check if customers are on the product page ($product is defined) before applying any additional conditions. This way, the filter is applied on the Tab Manager layout page and the tab can be reordered.

    Here’s some code to give you the basic idea.

    Here’s the original page including the code snippet: https://docs.woocommerce.com/document/tab-manager/#section-19

    I also pm’d the zip of the plugin.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Thanks for finding that. I’d like to try to integrate our plugin with the tabs manager. If I sent you a customized snippet, would you be able to test it out?

    Thread Starter Mike Oberdick

    (@mike_oberdick)

    Yes, absolutely.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Well after reading the docs a few times I don’t think this is going to work.

    >If your 3rd party tab relies on the global $product variable, the Tab Manager won’t be able to display the tab within its default settings, which means that the tab disappears :(.

    Our tabs function does required the global $product variable.

    If I understand correctly, it is using the same front-end tab output filter on the admin side to make the Tabs Manager plugin understand which tabs are available. This is not desirable at all but I understand why they have to do it. The issue is that our plugin’s tab data is encapsulated into classes; we can’t just use the front-end function on the admin.

    I can try something custom but I have very little confidence it is going to work. Here it goes…

    
    function third_party_tab( $tabs ) {
        global $product;
    
        $custom_product_tabs = $product ? get_yikes_custom_product_tabs( $product->id ) : null;
    
        if ( $product && empty( $custom_product_tabs ) ) {
            return $tabs;
        }
    
        foreach( $custom_product_tabs as $tab ) {
        	$tabs[ $tab['id'] ] = array(
        		'title'    => $tab['title'],
    	        'priority' => 30,
    	        'callback' => 'yikes_custom_product_tabs_callback',	
        	);
        }
    
        return $tabs;
    }
    add_filter( 'woocommerce_product_tabs', 'third_party_tab' );
    
    function yikes_custom_product_tabs_callback( $key, $tab ) {
    	echo apply_filters( 'the_content', $tab['content'] );
    }
    
    function get_yikes_custom_product_tabs( $product_id ) {
    	return get_post_meta( $product_id, 'yikes_woo_products_tabs', true );
    }
    Thread Starter Mike Oberdick

    (@mike_oberdick)

    No dice…any way to run a conditional statement that would hide the WooCommerce tabs and show the Yikes tabs if they are present? The new products that are being added to the site will only have the Yikes tabs so any products added moving forward will use this plugin’s tabs and won’t need the default WC tabs.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Mike,

    I don’t think it’s possible. Custom Tabs Manager is (somehow) removing our filter and only using their own filter. I don’t think I would be able to hijack their filter to allow our filter to run.

    I’m wondering if maybe you could export your existing Tabs Manager data and import it into Custom Product Tabs format. Do you know what the structure of Tabs Manager data looks like?

    For non-saved tabs, our data structure is really simple. It is saved as post meta under the key 'yikes_woo_products_tabs'. It is a serialized array that, for example, looks like this:

    array(2) {
      [0]=>
      array(3) {
        ["title"]=>
        string(16) "Saved Tab 1"
        ["id"]=>
        string(16) "saved-tab-1"
        ["content"]=>
        string(12) "banana phone"
      }
      [1]=>
      array(3) {
        ["title"]=>
        string(11) "Saved Tab 2"
        ["id"]=>
        string(11) "saved-tab-2"
        ["content"]=>
        string(14) "banana phone 2"
      }
    }

    Is there any way you could run a script to export Tabs Manager tabs and re-import them in the style of Custom Product Tabs? I might be able to help with this process.

    Let me know,
    Kevin.

    Thread Starter Mike Oberdick

    (@mike_oberdick)

    Interesting…I was thinking about that as a next step. So it looks like the product tabs are saved as custom post types (wc_product_tab) in wp_posts and the ID is used to associated it with post_meta (_product_tabs). So for one of the tabs it looks like this in post_meta:

    a:3:{s:20:”core_tab_description”;a:5:{s:8:”position”;i:0;s:4:”type”;s:4:”core”;s:2:”id”;s:11:”description”;s:5:”title”;s:11:”Description”;s:7:”heading”;s:19:”Product Description”;}s:17:”product_tab_22111″;a:4:{s:8:”position”;i:1;s:4:”type”;s:7:”product”;s:2:”id”;s:5:”22111″;s:4:”name”;s:12:”line-drawing”;}s:17:”product_tab_22112″;a:4:{s:8:”position”;i:2;s:4:”type”;s:7:”product”;s:2:”id”;s:5:”22112″;s:4:”name”;s:12:”photometrics”;}}

    Here is a snippet from the wp_posts entry:

    Here is the post on the front-end.

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    For anyone wondering, Mike and I worked together to import all of the tabs from WC Tabs Manager (https://woocommerce.com/products/woocommerce-tab-manager/) to Custom Product Tabs.

    For developers, this is a snippet of the code we used. (Note: please don’t copy this code and run it directly – there are some changes that need to made before running it in a real environment).

    // Get our products that have the'_product_tabs' post meta field
    	$wp_query_args = array(
    		'post_type'      => 'product',
    		'post_status'    => 'publish',
    		'meta_query'     => array(
    			'key'     => '_product_tabs',
    			'value'   => 'product',
    			'compare' => 'LIKE'
    		)
    	);
    
    	$products = new WP_Query( $wp_query_args );
    
    	// Make sure we have products
    	if ( $products->have_posts() ) {
    
    		global $post;
    
    		// Go through each product
    		while ( $products->have_posts() ) {
    			$products->the_post();
    
    			// Get the array of Tabs Manager tabs
    			$old_tab_data = get_post_meta( get_the_ID(), '_product_tabs', true );
    
    			// If we don't have tab data, go to the next product.
    			if ( empty( $old_tab_data ) || ! is_array( $old_tab_data ) ) {
    				continue;
    			}
    
    			// Get the array of YIKES Custom Product Tabs data
    			$new_tab_data = get_post_meta( get_the_ID(), 'yikes_woo_products_tabs', true );
    
    			// Make sure we're dealing with an array
    			$new_tab_data = is_array( $new_tab_data ) ? $new_tab_data : array();
    
    			foreach ( $old_tab_data as $tab ) {
    
    				// Don't import the description tab or we'll have duplicate descriptions
    				if ( $tab['type'] === 'core' ) {
    					continue;
    				}
    
    				// Get the wc_product_tab CPT object that this tab is based on
    				$wc_product_tab = get_post( $tab['id'] );
    
    				// Make sure we have a product tab
    				if ( empty( $wc_product_tab ) ) {
    					continue;
    				}
    
    				// Create the new tab structure for Custom Product Tabs
    				$new_tab_data[] = array(
    					'id'      => $tab['name'],                 // Slug
    					'title'   => $wc_product_tab->post_title,  // Title
    					'content' => $wc_product_tab->post_content // Content
    				);
    			}
    
    			update_post_meta( get_the_ID(), 'yikes_woo_products_tabs', $new_tab_data );
    		}
    Thread Starter Mike Oberdick

    (@mike_oberdick)

    Thank you so much Kevin…amazing support!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Using Multiple Custom Product Tab Plugins’ is closed to new replies.