我试图摆脱用户可以将鼠标悬停在主产品图像上并放大产品的功能。我尝试使用此代码,其他人已确认此代码有效,但没有任何更改。
function remove_image_zoom_support() {
remove_theme_support( \'wc-product-gallery-zoom\' );
}
add_action( \'wp\', \'remove_image_zoom_support\', 100 );
这是因为我正在使用的其他函数干扰了它吗?
这是我的函数文件:
<?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 );
?>
如果不是,是什么导致了此问题?
最合适的回答,由SO网友:LoicTheAztec 整理而成
这可以使用woocommerce_single_product_zoom_enabled
专用过滤器挂钩:
add_filter( \'woocommerce_single_product_zoom_enabled\', \'__return_false\' );
代码进入函数。活动子主题(或活动主题)的php文件。测试和工作。
可以使用woocommerce_single_product_zoom_enabled
专用过滤器挂钩。
钩子undocumented available parameters 选项数组中包括:
$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)
);
与一起使用
woocommerce_single_product_zoom_options
过滤器挂钩:
(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;
}
代码进入函数。活动子主题(或活动主题)的php文件。测试和工作。
相关:Adjusting product image\'s Zoom magnification factor in woocommerce 3