問題描述
默認(rèn)情況下,WooCommerce 中的產(chǎn)品標(biāo)簽會(huì)自動(dòng)打開第一個(gè).是否可以默認(rèn)將它們?nèi)筷P(guān)閉,需要您單擊它才能查看更多內(nèi)容?
我嘗試了以下代碼,但似乎沒有做到.也許有一個(gè) PHP 代碼可以完成它或一些簡單的東西?
我已經(jīng)嘗試過,但運(yùn)氣不佳:
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);
更新 - 你應(yīng)該試試:
//條件顯示根據(jù)選擇的運(yùn)輸方式隱藏結(jié)帳字段add_action('wp_footer', 'close_all_product_tabs');函數(shù) close_all_product_tabs(){//僅在單個(gè)產(chǎn)品頁面上如果(!is_product())返回;?><腳本>jQuery(函數(shù)($){設(shè)置超時(shí)(功能(){$('#tab-description').hide( function(){$( 'li#tab-title-description' ).removeClass('active');});}, 200);});<?php}
此代碼位于活動(dòng)子主題(或主題)的 function.php 文件或任何插件文件中.
經(jīng)過測(cè)試并有效
<小時(shí)><塊引用>這是對(duì)作者主題結(jié)構(gòu)的專門編輯,是定制的:
jQuery(function($){jQuery(函數(shù)($){設(shè)置超時(shí)(功能(){$('#tab-description').hide( function(){$( 'li#description_tab' ).removeClass('active');});}, 200);});});
<小時(shí)>
現(xiàn)在在您的主題中,有一個(gè)專門用于所有內(nèi)容標(biāo)簽的
這個(gè)容器有一個(gè)灰色的邊框和一些填充,所以當(dāng)你隱藏描述選項(xiàng)卡時(shí),它就像一個(gè)帶有灰色邊框的白色扁平矩形一樣空著,這不是很好.所以你應(yīng)該隱藏它或給他0不透明度
隱藏它您可以通過許多其他方式使用:
- `$('div.tab-panels').addClass('hidden');` 以及這個(gè)隱藏"類的一些 CSS 規(guī)則- `$('div.tab-panels').css('opacity', '0');`- `$('div.tab-panels').css('visibility', 'hidden');`
一旦隱藏,您將需要在單擊按鈕時(shí)使其可見(這是更難的部分):
-`$('div.tab-panels').removeClass('hidden');`- `$('div.tab-panels').css('opacity', '1');`- `$('div.tab-panels').css('visibility', 'visible');`
最難的是讓點(diǎn)擊事件觸發(fā)這個(gè)......
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…
這篇關(guān)于默認(rèn)關(guān)閉 WooCommerce 產(chǎn)品標(biāo)簽的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!