問題描述
默認情況下,WooCommerce 中的產品標簽會自動打開第一個.是否可以默認將它們全部關閉,需要您單擊它才能查看更多內容?
我嘗試了以下代碼,但似乎沒有做到.也許有一個 PHP 代碼可以完成它或一些簡單的東西?
我已經嘗試過,但運氣不佳:
setTimeout(function() {var $tabs = jQuery( '.wc-tabs, ul.tabs' ).first();$tabs.parent().find('#tab-description').hide();$tabs.parent().find('.tab-title-description').removeClass('active');}, 10);
更新 - 你應該試試:
//條件顯示根據選擇的運輸方式隱藏結帳字段add_action('wp_footer', 'close_all_product_tabs');函數 close_all_product_tabs(){//僅在單個產品頁面上如果(!is_product())返回;?><腳本>jQuery(函數($){設置超時(功能(){$('#tab-description').hide( function(){$( 'li#tab-title-description' ).removeClass('active');});}, 200);});<?php}
此代碼位于活動子主題(或主題)的 function.php 文件或任何插件文件中.
經過測試并有效
<小時><塊引用>這是對作者主題結構的專門編輯,是定制的:
jQuery(function($){jQuery(函數($){設置超時(功能(){$('#tab-description').hide( function(){$( 'li#description_tab' ).removeClass('active');});}, 200);});});
<小時>
現在在您的主題中,有一個專門用于所有內容標簽的
這個容器有一個灰色的邊框和一些填充,所以當你隱藏描述選項卡時,它就像一個帶有灰色邊框的白色扁平矩形一樣空著,這不是很好.所以你應該隱藏它或給他0不透明度
隱藏它您可以通過許多其他方式使用:
- `$('div.tab-panels').addClass('hidden');` 以及這個隱藏"類的一些 CSS 規則- `$('div.tab-panels').css('opacity', '0');`- `$('div.tab-panels').css('visibility', 'hidden');`
一旦隱藏,您將需要在單擊按鈕時使其可見(這是更難的部分):
-`$('div.tab-panels').removeClass('hidden');`- `$('div.tab-panels').css('opacity', '1');`- `$('div.tab-panels').css('visibility', 'visible');`
最難的是讓點擊事件觸發這個......
By default Product Tabs in WooCommerce auto opens the first one. Is it possible to have them all closed by default, requiring you to click it to see more?
I have tried the following code, but it does not seem to do it. Perhaps there is a PHP code that does it or something simple?
I already tried this without luck:
setTimeout(function() {
var $tabs = jQuery( '.wc-tabs, ul.tabs' ).first();
$tabs.parent().find('#tab-description').hide();
$tabs.parent().find( '.tab-title-description' ).removeClass('active');
}, 10);
解決方案 Updated - You should try instead:
// Conditional Show hide checkout fields based on chosen shipping methods
add_action( 'wp_footer', 'close_all_product_tabs' );
function close_all_product_tabs(){
// Only on single product pages
if( ! is_product() ) return;
?>
<script>
jQuery(function($){
setTimeout(function() {
$('#tab-description').hide( function(){
$( 'li#tab-title-description' ).removeClass('active');
});
}, 200);
});
</script>
<?php
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works
This is an edit specifically to the authors theme structure which is customized:
jQuery(function($){
jQuery(function($){
setTimeout(function() {
$('#tab-description').hide( function(){
$( 'li#description_tab' ).removeClass('active');
});
}, 200);
});
});
Now in your theme, there is specifically a <div>
container for all your content tabs, that WooCommerce don't have by default:
<div class="tab-panels">
This container has a grey border and some padding, so when you hide the description tab, it stays empty like a white flat rectangle with a grey border, which is not very nice. so you should need to hide it or to give him 0 opacity
To hide it You can handle this in many other ways using:
- `$('div.tab-panels').addClass('hidden');` and some CSS rules for this 'hidden' class
- `$('div.tab-panels').css('opacity', '0');`
- `$('div.tab-panels').css('visibility', 'hidden');`
Once hidden, you will need to make it visible when a button is clicked (and this is the harder part):
- `$('div.tab-panels').removeClass('hidden');`
- `$('div.tab-panels').css('opacity', '1');`
- `$('div.tab-panels').css('visibility', 'visible');`
The hardest thing will be to get the click event to trigger this…
這篇關于默認關閉 WooCommerce 產品標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!