以下即使用WooCommerce专用woocommerce_single_product_carousel_options
过滤器钩子和使用 WordPresswp_is_mobile()
条件标签:
add_filter( 'woocommerce_single_product_carousel_options', 'filter_single_product_carousel_options' );
function filter_single_product_carousel_options( $options ) {
if ( wp_is_mobile() ) {
$options['smoothHeight'] = true; // Already "true" by default
$options['controlNav'] = true; // Option 'thumbnails' by default
$options['animation'] = "slide"; // Already "slide" by default
$options['slideshow'] = false; // Already "false" by default
}
return $options;
}
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
请参阅 WooCommerce相关默认设置woocommerce_single_product_carousel_options hook https://github.com/woocommerce/woocommerce/blob/4.2.2/includes/class-wc-frontend-scripts.php#L484-L497:
'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options',
array(
'rtl' => is_rtl(),
'animation' => 'slide',
'smoothHeight' => true,
'directionNav' => false,
'controlNav' => 'thumbnails',
'slideshow' => false,
'animationSpeed' => 500,
'animationLoop' => false, // Breaks photoswipe pagination if true.
'allowOneSlide' => false,
)
),
文档:WordPress 开发者资源 -wp_is_mobile()条件函数 https://developer.wordpress.org/reference/functions/wp_is_mobile/