I’m trying to get rid of the function where users can hover over the main product image and zoom into the product. I tried using this code, which has been confirmed by others to work, but nothing changed.
function remove_image_zoom_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
add_action( 'wp', 'remove_image_zoom_support', 100 );
Is this because some other function I’m using is interfering with it?
Here is my functions file:
<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
$parent_style="parent-style"; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
wp_enqueue_style( 'my-google-fonts', 'http://fonts.googleapis.com/css?family=Lekton', false );
}
//* Redirect archive pages to the home page
function redirect_to_home( $query ){
if(is_archive() ) {
wp_redirect( home_url() );
exit;
}
}
add_action( 'parse_query', 'redirect_to_home' );
//* Add CPT taxonomy terms to body class
function add_taxonomy_to_single( $classes ) {
if ( is_single() ) {
global $post;
$my_terms = get_the_terms( $post->ID, 'skill' );
if ( $my_terms && ! is_wp_error( $my_terms ) ) {
foreach ($my_terms as $term) {
$classes[] = $term->slug;
}
}
}
return $classes;
}
add_filter( 'body_class', 'add_taxonomy_to_single' );
//* Add page slug body class
function add_slug_body_class( $classes ) {
global $post;
if ( isset( $post ) ) {
$classes[] = $post->post_type . '-' . $post->post_name;
}
return $classes;
}
add_filter( 'body_class', 'add_slug_body_class' );
//* Unload Gutenberg Block Editor
add_action( 'wp_print_styles', 'wps_deregister_styles', 100 );
function wps_deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
//* Use Google's jQuery
add_action('init', 'use_jquery_from_google');
function use_jquery_from_google () {
if (is_admin()) {
return;
}
global $wp_scripts;
if (isset($wp_scripts->registered['jquery']->ver)) {
$ver = $wp_scripts->registered['jquery']->ver;
} else {
$ver="3.4.0";
}
wp_deregister_script('jquery');
wp_register_script('jquery', "//ajax.googleapis.com/ajax/libs/jquery/$ver/jquery.min.js", false, $ver);
}
//* Remove Testimonials post type
add_action( 'init', 'remove_testimonial_cpt', 1000 );
function remove_testimonial_cpt() {
unregister_post_type( 'testimonial' );
}
//* Remove WYSIWYG editor from products
add_action('init', 'init_remove_support',100);
function init_remove_support(){
$post_type="product";
remove_post_type_support( $post_type, 'editor');
}
//* Change gallery thumbnail sizes
add_filter( 'woocommerce_get_image_size_gallery_thumbnail', function( $size ) {
return array(
'width' => 132,
'height' => 162,
'crop' => 0,
);
});
//* Remove Proceed to Checkout button on Cart page
remove_action( 'woocommerce_proceed_to_checkout',
'woocommerce_button_proceed_to_checkout', 20);
//* Remove thumbnails from Cart page
add_filter( 'woocommerce_cart_item_thumbnail', '__return_false' );
//* Remove results count and dropdown on main shop page
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
//* Remove additional information tab on single shop page
add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
function woo_remove_product_tabs( $tabs ) {
unset( $tabs['additional_information'] );
return $tabs;
}
//* Add gallery captions for shop items
function gcw_insert_captions( $html, $attachment_id ) {
$captions="";
$title = get_post_field( 'post_title', $attachment_id );
if( !empty( $title ) ) {
$captions .= '<h3>' . esc_html( $title ) . '</h3>';
}
if( !empty( $captions ) ) {
$captions="<div class="gcw-caption">" . $captions . '</div>';
$html = preg_replace('~<\/div>$~', $captions . '</div>', $html );
}
return $html;
}
add_filter( 'woocommerce_single_product_image_thumbnail_html', 'gcw_insert_captions', 10, 2 );
//* Remove hover zoom
function remove_image_zoom_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
}
add_action( 'wp', 'remove_image_zoom_support', 100 );
?>
If not, what could be causing this issue?
3 Answers
This is possible using woocommerce_single_product_zoom_enabled
dedicated filter hook:
add_filter( 'woocommerce_single_product_zoom_enabled', '__return_false' );
Code goes in functions.php file of your active child theme (or active theme). Tested and work.
It is possible using woocommerce_single_product_zoom_enabled
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) );
Usage with woocommerce_single_product_zoom_options
filter hook:
1) Disable the zoom:
add_filter( 'woocommerce_single_product_zoom_options', 'custom_single_product_zoom_options', 10, 3 );
function custom_single_product_zoom_options( $zoom_options ) {
// Disable zoom magnify:
$zoom_options['magnify'] = 0;
return $zoom_options;
}
2) Change zoom event option:
add_filter( 'woocommerce_single_product_zoom_options', 'custom_single_product_zoom_options', 10, 3 );
function custom_single_product_zoom_options( $zoom_options ) {
// Changing the zoom event option:
$zoom_options['on'] = 'click';
return $zoom_options;
}
Code goes in functions.php file of your active child theme (or active theme). Tested and work.
Related: Adjusting product image’s Zoom magnification factor in woocommerce 3