如何更改 WooCommerce 子主题中的 FlexSlider 选项

How to Change FlexSlider options in WooCommerce child theme

我刚刚更改了 class-wc-frontend-scripts.php 文件的这一部分,该文件位于 Woocommerce 的“includes”文件夹中:

'flexslider' => apply_filters( 'woocommerce_single_product_carousel_options',
    array(
        'rtl'            => is_rtl(),
        'animation'      => 'fade',
        'easing'      => 'swing',
        'smoothHeight'   => true,
        'directionNav'   => false,
        'controlNav'     => true,
        'slideshow'      => true,
        'touch'      => true,
        'animationSpeed' => 1200,
        'slideshowSpeed' => 3500,
        'animationLoop'  => true, // Breaks photoswipe pagination if true.
        'allowOneSlide'  => true,
        'prevText' => "<",           //String: Set the text for the "previous" directionNav item
        'nextText' => ">",               //String: Set the text for the "next" directionNav item
    )
),

如何转为子主题?

不要覆盖任何核心文件...相反,您可以使用 woocommerce_single_product_carousel_options 过滤器挂钩,如下所示:

add_filter( 'woocommerce_single_product_carousel_options', 'filter_single_product_carousel_options' );
function filter_single_product_carousel_options( $args ) {
    $args['animation']      = 'fade';
    $args['easing']         = 'swing';
    $args['controlNav']     = true;
    $args['slideshow']      = true;
    $args['touch']          = true;
    $args['animationSpeed'] = 1200;
    $args['slideshowSpeed'] = 3500;
    $args['animationLoop']  = true; // Breaks photoswipe pagination if true.
    $args['allowOneSlide']  = true;
    $args['prevText']       = "<";  // String - Set the text for the "previous" directionNav item
    $args['nextText']       = ">";  // String - Set the text for the "next" directionNav item
    
    return $args;
}

代码进入您的活动子主题(或活动主题)的 functions.php 文件。它应该可以工作。

相关: