在WooCommerce产品库中阻止变化图像放置

时间:2019-01-28 22:30:31

标签: javascript jquery wordpress woocommerce

我有一种想阻止的行为。基本上,变体图片会放置在产品库中,我希望这种情况不会发生。

这是发生这种情况的js文件。

https://github.com/woocommerce/woocommerce/blob/master/assets/js/frontend/add-to-cart-variation.js

我认为它发生在560行中。我的问题是,如何阻止该部分的发生?

如果您不想转到链接,请输入代码。

/**
 * Sets product images for the chosen variation
 */
$.fn.wc_variations_image_update = function( variation ) {
    var $form             = this,
        $product          = $form.closest( '.product' ),
        $product_gallery  = $product.find( '.images' ),
        $gallery_nav      = $product.find( '.flex-control-nav' ),
        $gallery_img      = $gallery_nav.find( 'li:eq(0) img' ),
        $product_img_wrap = $product_gallery.find( '.woocommerce-product-gallery__image, .woocommerce-product-gallery__image--placeholder' ).eq( 0 ),
        $product_img      = $product_img_wrap.find( '.wp-post-image' ),
        $product_link     = $product_img_wrap.find( 'a' ).eq( 0 );

    if ( variation && variation.image && variation.image.src && variation.image.src.length > 1 ) {
        // See if the gallery has an image with the same original src as the image we want to switch to.
        var galleryHasImage = $gallery_nav.find( 'li img[data-o_src="' + variation.image.gallery_thumbnail_src + '"]' ).length > 0;

        // If the gallery has the image, reset the images. We'll scroll to the correct one.
        if ( galleryHasImage ) {
            $form.wc_variations_image_reset();
        }

        // See if gallery has a matching image we can slide to.
        var slideToImage = $gallery_nav.find( 'li img[src="' + variation.image.gallery_thumbnail_src + '"]' );

        if ( slideToImage.length > 0 ) {
            slideToImage.trigger( 'click' );
            $form.attr( 'current-image', variation.image_id );
            window.setTimeout( function() {
                $( window ).trigger( 'resize' );
                $product_gallery.trigger( 'woocommerce_gallery_init_zoom' );
            }, 20 );
            return;
        }

        $product_img.wc_set_variation_attr( 'src', variation.image.src );
        $product_img.wc_set_variation_attr( 'height', variation.image.src_h );
        $product_img.wc_set_variation_attr( 'width', variation.image.src_w );
        $product_img.wc_set_variation_attr( 'srcset', variation.image.srcset );
        $product_img.wc_set_variation_attr( 'sizes', variation.image.sizes );
        $product_img.wc_set_variation_attr( 'title', variation.image.title );
        $product_img.wc_set_variation_attr( 'data-caption', variation.image.caption );
        $product_img.wc_set_variation_attr( 'alt', variation.image.alt );
        $product_img.wc_set_variation_attr( 'data-src', variation.image.full_src );
        $product_img.wc_set_variation_attr( 'data-large_image', variation.image.full_src );
        $product_img.wc_set_variation_attr( 'data-large_image_width', variation.image.full_src_w );
        $product_img.wc_set_variation_attr( 'data-large_image_height', variation.image.full_src_h );
        $product_img_wrap.wc_set_variation_attr( 'data-thumb', variation.image.src );
        $gallery_img.wc_set_variation_attr( 'src', variation.image.gallery_thumbnail_src );
        $product_link.wc_set_variation_attr( 'href', variation.image.full_src );
    } else {
        $form.wc_variations_image_reset();
    }

    window.setTimeout( function() {
        $( window ).trigger( 'resize' );
        $form.wc_maybe_trigger_slide_position_reset( variation );
        $product_gallery.trigger( 'woocommerce_gallery_init_zoom' );
    }, 20 );
};

0 个答案:

没有答案