Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

php - Adjusting product image's Zoom magnification factor in woocommerce 3

With Woocommerce, I'm using the Storefront theme and have been wondering if there is a way to adjust the zooming level imposed on the product image upon hovering on it.

Any help is greatly appreciated.

question from:https://stackoverflow.com/questions/65880902/decrease-the-default-zoom-photoswipe

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is possible using woocommerce_single_product_zoom_options dedicated filter hook.

The hook undocumented available parameters in the options array are:

$zoom_options = array (
    'url' => false,
    'callback' => false,
    'target' => false,
    'duration' => 120, // Transition in milli seconds (default is 120)
    'on' => 'mouseover', // other options: grab, click, toggle (default is mouseover)
    'touch' => true, // enables a touch fallback
    'onZoomIn' => false,
    'onZoomOut' => false,
    'magnify' => 1, // Zoom magnification: (default is 1  |  float number between 0 and 1)
);

Related: Available parameters details for WooCommerce product image zoom options

Usage with woocommerce_single_product_zoom_options filter hook to change the magnification level (for example we mill minimize the zoom level a bit less):

add_filter( 'woocommerce_single_product_zoom_options', 'custom_single_product_zoom_options' );
function custom_single_product_zoom_options( $zoom_options ) {
    // Changing the magnification level:
    $zoom_options['magnify'] = 0.7;

    return $zoom_options;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and work.

Before with default magnification (set to 1):

enter image description here

Before with magnification set to 0.7:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...