Support » Plugin: Multivendor Marketplace Solution for WooCommerce - WC Marketplace » Conflict with WooCommerce Tab Manager

  • Resolved meglio

    (@meglio)


    When activating the following plugin:

    https://woocommerce.com/products/woocommerce-tab-manager/

    I see the following error:

    Fatal error: Uncaught Error: Call to a member function get_id() on null in /home/cheesewp/web/wp-content/plugins/dc-woocommerce-multi-vendor/classes/class-wcmp-product.php:1456 Stack trace: #0 /home/cheesewp/web/wp-includes/class-wp-hook.php(286): WCMp_Product->wcmp_customer_questions_and_answers_tab(Array) #1 /home/cheesewp/web/wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array) #2 /home/cheesewp/web/wp-content/plugins/woocommerce-tab-manager/woocommerce-tab-manager.php(664): apply_filters(‘woocommerce_pro…’, Array) #3 /home/cheesewp/web/wp-content/plugins/woocommerce-tab-manager/admin/woocommerce-tab-manager-admin-functions.php(160): WC_Tab_Manager->get_third_party_tabs() #4 /home/cheesewp/web/wp-content/plugins/woocommerce-tab-manager/admin/woocommerce-tab-manager-admin-global-layout.php(64): wc_tab_manager_sortable_product_tabs(false) #5 /home/cheesewp/web/wp-includes/class-wp-hook.php(286): wc_tab_manager_render_layout_page(”) #6 /home/cheesewp/web/wp-includes/class-wp-hook.php(310): WP_Hook->apply_f in /home/cheesewp/web/wp-content/plugins/dc-woocommerce-multi-vendor/classes/class-wcmp-product.php on line 1456

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Dualcube

    (@dualcube)

    Hi, after hearing from you, we checked the same on our side, didn’t face any such error, see this video, we have tested this by enabling the debug mode also: https://www.useloom.com/share/713fc1e2003645d8930168d3b31da8cb

    It seems like some product might not be there on the site, that is why the function get_id() is blank.

    Can you please share us one video so that we can see how you are getting this error. We will wait for your reply.

    Thread Starter meglio

    (@meglio)

    @dualcube so, click on “Configure” for the Tab Manager plugin in the plugins list. When the configuration page opens, switch to the “Default Tab Layout” section and you’ll the see the error.

    • This reply was modified 3 years ago by meglio.
    • This reply was modified 3 years ago by meglio.
    Thread Starter meglio

    (@meglio)

    @dualcube, I think the issue is with how you implement the wcmp_customer_questions_and_answers_tab hook.

    It starts with:

    global $product;
    $vendor = get_wcmp_product_vendors($product->get_id());

    However, $product is not always available, hence the issue.

    Compare to the product_vendor_tab() hook in your plugin:

    global $product;
     if ($product) { /* the logic is wrapped */ }

    Here, you wrap the logic in an if ($product), which looks the correct way to do it.

    You may also want to do the same wrapping in product_single_product_multivendor_tab().

    I can confirm that wrapping the logic in an if fixes the issue, i.e. no error is thrown when the fix applied. However, it doesn’t list any product tabs created by your plugin either. Will you be able to fix it?

    The WooCommerce Tab Manager home page says:

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

    So that’s what I hoped for, but the detection did not happen.

    P.S. You may also want to unmark this thread as “Resolved”.

    • This reply was modified 3 years ago by meglio.
    • This reply was modified 3 years ago by meglio.
    Thread Starter meglio

    (@meglio)

    @dualcube, so, you may want to look at the get_third_party_tabs() function in the WooCommerce Tab Manager plugin. That’s where they collect all tabs created by 3rd party plugins by calling:

    $tabs = (array) apply_filters( 'woocommerce_product_tabs', array() );

    Since no $product is available in admin pages, the WCMp returns no custom tabs for it, so the tabs get not detected.

    The PHPDOC of get_third_party_tabs lists hooks that you can use to integrate tightly with their plugin. It is worth the effort cause that plugin is listed in the official WooCommerce extensions store.

    In the meantime, I implemented the following workaround, which you’re free to use and copy-paste in your plugin to improve compatibility:

    <?php
    # Make WCMp compatible with WooCommerce Product Tab Manager by letting the latter
    # recognize custom tabs created by the former.
    add_filter('woocommerce_product_tabs', function($tabs) {
    
        # Only admin pages
        if (!is_admin()) {
            return $tabs;
        }
    
        # Only calls by WC_Tab_Manager::get_third_party_tabs()
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        $isCallerTabManagerAdminPanel = false;
        foreach ($trace as $traceItem) {
            if (array_key_exists('function', $traceItem)
                && array_key_exists('class', $traceItem)
                && $traceItem['function'] == 'get_third_party_tabs'
                && $traceItem['class'] == 'WC_Tab_Manager') {
                $isCallerTabManagerAdminPanel = true;
                break;
            }
        }
        if (!$isCallerTabManagerAdminPanel) {
            return $tabs;
        }
    
        # Declare custom tabs as found in WCMp
    
        if (!array_key_exists('policies', $tabs)) {
            $tabs['policies'] = [
                'title' => apply_filters('wcmp_policies_tab_title', __('Policies', 'dc-woocommerce-multi-vendor')),
                'priority' => 30,
            ];
        }
    
        if (!array_key_exists('vendor', $tabs)) {
            $tabs['vendor'] = array(
                'title' => __('Vendor', 'dc-woocommerce-multi-vendor'),
                'priority' => 20,
            );
        }
    
        if (!array_key_exists('singleproductmultivendor', $tabs)) {
            $tabs['singleproductmultivendor'] = array(
                'title' => apply_filters('wcmp_more_vendors_tab', __('More Offers', 'dc-woocommerce-multi-vendor')),
                'priority' => 80,
            );
        }
    
        if (!array_key_exists('singleproductmultivendor', $tabs)) {
            $tabs['wcmp_customer_qna'] = array(
                'title' => __('Questions and Answers', 'dc-woocommerce-multi-vendor'),
                'priority' => 40,
            );
        }
    
        return $tabs;
    
    }, 2);
    • This reply was modified 3 years ago by meglio.
    Plugin Author Dualcube

    (@dualcube)

    @meglio, thanks for sharing the code snippet with us. You can also contribute directly via our GitHub : https://github.com/dualcube/dc-woocommerce-multi-vendor

    We are going to publish our plugin contributor list soon, we would love to add you there. Can you please get in touch with us over contribute@wc-marketplace.com

    Thread Starter meglio

    (@meglio)

    @dualcube, there’s an issue in the code snipped above.

    The if check is the same for two blocks:

    if (!array_key_exists('singleproductmultivendor'))

    For the “Questions and Answers” tab, the check should be:

    if (!array_key_exists('wcmp_customer_qna'))

    Thread Starter meglio

    (@meglio)

    P.S. Sent you an email to contribute@wc-marketplace.com as suggested.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conflict with WooCommerce Tab Manager’ is closed to new replies.