将简短描述移动到 Woocommerce 单个产品页面中的选项卡中 [英] Move short description into tabs in Woocommerce single product pages

查看:72
本文介绍了将简短描述移动到 Woocommerce 单个产品页面中的选项卡中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 woocommerce 单一产品页面中,如何将产品简短描述移动到自定义产品选项卡中,其中描述和附加信息?

In woocommerce Single Product pages, how do I move the product short description into a custom product tab where the description and the additional information are?

我已将描述和附加信息选项卡从标准位置移至产品摘要所在的右侧.但是,我想将产品摘要插入一个选项卡中,因此基本上它将是 3 个选项卡.

I have moved the description and additional information tab from the standard position to the right side where the product summary is. However I would like to insert the product summary into a tab so essentially it will be 3 tabs.

我用来将标签移动到图像右侧的代码是:

The code I have used to move the tabs to the right of the image is:

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 30 );

推荐答案

您仍然保留以下更改选项卡位置的内容(就像您已经做的那样):

You still keep the following that change the tabs location (as you already do):

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 30 );

然后,以下内容会将简短描述的位置更改为自定义产品选项卡:

Then, the following will change the location of short description to a custom product tab:

// Remove short description
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );

// Add short description to a custom product tab
add_filter( 'woocommerce_product_tabs', 'add_custom_product_tab', 10, 1 );
function add_custom_product_tab( $tabs ) {

    $custom_tab = array(
        'custom_tab' =>  array(
            'title' => __( "Short description", "woocommerce" ),
            'priority' => 12,
            'callback' => 'short_description_tab_content'
        )
    );
    return array_merge( $custom_tab, $tabs );
}

// Custom product tab content
function short_description_tab_content() {
    global $post, $product;

    $short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );

    if ( ! $short_description ) {
        return;
    }

    echo '<div class="woocommerce-product-details__short-description">' . $short_description . '</div>'; // WPCS: XSS ok.
}

代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.

Code goes on function.php file of your active child theme (or active theme). Tested and works.

这篇关于将简短描述移动到 Woocommerce 单个产品页面中的选项卡中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆