【发布时间】:2023-03-17 22:09:01
【问题描述】:
默认情况下,在单个产品页面上启用选项 'controlNav' = 'thumbnails'。台式机没问题。但在移动设备上,我想成为 'controlNav' = true(点)。我尝试使用 ajax 来实现,但我认为我需要以某种方式使用 flex 幻灯片刷新该片段以应用过滤器。看不懂。
在JS文件中:
if (window.matchMedia('(max-width: 800px)').matches) {
$.ajax({
url: wc_add_to_cart_params.ajax_url,
data: { action: 'mobile_slider'},
type: 'POST'
})
.then(res => console.log('works', res))
}
在functions.php中:
function hellenik_change_slider_mobile()
{
add_filter('woocommerce_single_product_carousel_options', 'hellenik_update_woo_flexslider_options');
function hellenik_update_woo_flexslider_options($options)
{
$options['smoothHeight'] = true;
$options['controlNav'] = true;
$options['animation'] = "slide";
$options['slideshow'] = false;
return $options;
}
wp_die();
}
add_action('wp_ajax_mobile_slider', 'hellenik_change_slider_mobile');
add_action('wp_ajax_nopriv_mobile_slider', 'hellenik_change_slider_mobile');
【问题讨论】:
标签: javascript php wordpress woocommerce flexslider