【发布时间】:2021-06-20 10:18:39
【问题描述】:
我在 WordPress 平台下使用 WooCommerce 插件,我正在尝试更改 single-product.php 页面中的默认选项卡。
所以现在我有第二个选项卡处于活动状态,我想将第一个选项卡更改为默认活动选项卡。
我已经使用 woocommerce_product_tabs 过滤钩更改了优先级:
add_filter('woocommerce_product_tabs', function($tabs) {
global $post, $product; // Access to the current product or post
$custom_tab_title = get_field('props', $post->ID);
$tabs['reviews']['priority'] = 10;
if (!empty($custom_tab_title)) {
$tabs['awp-' . sanitize_title('props')] = [
'title' => 'אביזרים',
'callback' => 'awp_custom_woocommerce_tabs',
'priority' => 5
];
}
return $tabs;
});
我还尝试使用基于 active 类的 jQuery 更改它,如下所示:
jQuery(document).ready(function($){
console.log( "ready!" );
jQuery('.reviews_tab').removeClass('active');
jQuery('#tab-title-awp-props').addClass('active');
});
到目前为止没有任何效果。
如何更改 WooCommerce 单个产品页面中的默认活动选项卡?
【问题讨论】:
-
可以尝试触发点击事件:
jQuery('#tab-title-awp-props').trigger('click'); -
@David 很遗憾没有奏效。当我使用 lighthouse 跟踪页面加载过程时,我看到页面在标签真正加载之前就准备好了,所以它影响了 javascript 功能。
标签: javascript php jquery wordpress woocommerce