【问题标题】:Move short description into tabs in Woocommerce single product pages将简短描述移动到 Woocommerce 单个产品页面中的选项卡中
【发布时间】:2019-08-13 23:25:27
【问题描述】:

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

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

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

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 );

【问题讨论】:

    标签: php wordpress woocommerce tabs product


    【解决方案1】:

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

    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 );
    

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

    // 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 文件中。经过测试并且可以工作。

    【讨论】:

    • 谢谢!我现在遇到的问题是它在底部和右上角重复,我如何摆脱底部水龙头而只在右边?
    • @EmbroideryKing 我不知道你在说什么。此代码经过测试,可满足您的要求……
    • 这是我目前的代码。如您所见,选项卡仍显示在下面。我希望它们不出现在那里,而只出现在图片的右侧。至于名为 ppom 的插件,我仍然希望它出现在底部。这是我的代码
    • @EmbroideryKing 您需要保留您的问题代码并添加我的问题代码(如我的回答中所述)。您最初的问题是将简短描述移动到产品选项卡中,我的代码就是这样做的。
    猜你喜欢
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 2020-06-08
    相关资源
    最近更新 更多