![](/img/trans.png)
[英]Woocommerce how to move the product tabs before the short description
[英]Move short description into tabs in Woocommerce single product pages
在 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 );
您仍然保留以下更改選項卡位置的內容(就像您已經做的那樣):
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 文件中。 測試和工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.