Adding multiple tabs to WooCommerce single product pages

前端 未结 3 1997
暖寄归人
暖寄归人 2020-12-01 20:16

I am trying to add three custom tabs to WooCommerce. I have the code below and two of them show up but for some reason the attribute description tab does not show on the pag

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-01 20:43

    As you are using 4 times the same hook woocommerce_product_tabs, your problem comes from the highest priority on the first one. Instead you should use it only one time, merging that 4 hooked functions in one.

    Here is your functional tested code, changed a little bit:

    add_filter( 'woocommerce_product_tabs', 'woo_custom_product_tabs' );
    function woo_custom_product_tabs( $tabs ) {
    
        // 1) Removing tabs
    
        unset( $tabs['description'] );              // Remove the description tab
        // unset( $tabs['reviews'] );               // Remove the reviews tab
        unset( $tabs['additional_information'] );   // Remove the additional information tab
    
    
        // 2 Adding new tabs and set the right order
    
        //Attribute Description tab
        $tabs['attrib_desc_tab'] = array(
            'title'     => __( 'Desc', 'woocommerce' ),
            'priority'  => 100,
            'callback'  => 'woo_attrib_desc_tab_content'
        );
    
        // Adds the qty pricing  tab
        $tabs['qty_pricing_tab'] = array(
            'title'     => __( 'Quantity Pricing', 'woocommerce' ),
            'priority'  => 110,
            'callback'  => 'woo_qty_pricing_tab_content'
        );
    
        // Adds the other products tab
        $tabs['other_products_tab'] = array(
            'title'     => __( 'Other Products', 'woocommerce' ),
            'priority'  => 120,
            'callback'  => 'woo_other_products_tab_content'
        );
    
        return $tabs;
    
    }
    
    // New Tab contents
    
    function woo_attrib_desc_tab_content() {
        // The attribute description tab content
        echo '

    Description

    '; echo '

    Custom description tab.

    '; } function woo_qty_pricing_tab_content() { // The qty pricing tab content echo '

    Quantity Pricing

    '; echo '

    Here\'s your quantity pricing tab.

    '; } function woo_other_products_tab_content() { // The other products tab content echo '

    Other Products

    '; echo '

    Here\'s your other products tab.

    '; }

    This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    Tested and works.


    In the same hook, you can:

    • Remove tabs
    • Add tabs
    • Reorder tabs

    Related official documentation: Editing product data tabs

提交回复
热议问题