问题描述
默认情况下,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 产品标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End
相关推荐
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20
php开发问题
168
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23
php开发问题
287
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23
php开发问题
11
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23
php开发问题
4
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23
php开发问题
17
热门文章
1nohup:忽略输入并将输出附加到“nohup.out"
2在控制台中出错:无法加载资源:net::ERR_CONNECTION_RESET
3如何将 LDAP 时间戳转换为 Unix 时间戳
4不推荐使用常量 FILTER_SANITIZE_STRING
5APACHE 崩溃:父进程:子进程以状态 3221225477 退出 -- 正在重新启动
6PHP通过phpspreadsheet导入Excel日期数据处理方法
7Analytics API 返回:错误请求 - invalid_grant
8“tlsv1 警报内部错误"握手时
热门精品源码
最新VIP资源
1多功能实用站长工具箱html功能模板
2多风格简历在线生成程序网页模板
3论文相似度查询系统源码
4响应式旅游景点宣传推广页面模板
5在线起名宣传推广网站源码
6酷黑微信小程序网站开发宣传页模板
7房产销售交易中介网站模板
8小学作业自动生成程序


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)