Woocommerce JQuery用缩略图替换主要产品图像

时间:2015-06-21 09:39:50

标签: javascript jquery wordpress onclick woocommerce

所以我一直在实施"主要产品形象交换"从今天早上起,我就到了那里。在更改了我的网站的完整设计后,我想重新进行调整,但它根本不起作用。

过去我曾使用过这段代码:

jQuery(document).on('click','.thumbnails .zoom', function(){
    var photo_fullsize =  jQuery(this).find('img').attr('src').replace('-58x58','');
    jQuery('.woocommerce_main_image img').attr('src', + photo_fullsize + );
    return false;
});   

Src:Replace main image with thumbnail on click with jQuery

我已将此添加到我的functions.php

add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
    wp_enqueue_script(
        'productgallery', // name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . '/js/productgallery.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );
}

我现在的问题是,缩略图会直接将我带到图像中。没有交换也没有。我正在玩这些课程,因为我认为也许woocommerce在更新过程中改变了它们......

课程的更多输入 - 主要产品图像&缩略图:

<div class="product_image">
<a class="woocommerce-main-image zoom" data-rel="lightbox[product-gallery]"    title="1422571149-171" itemprop="image" href="MY WEBSITE/... .jpg">
<img class="attachment-shop_single wp-post-image" width="456" height="456" title="1422571149-171" src="MY WEBSITE/... .jpg-456x456.jpg">
</a>

</div>
<div class="product_thumbnails">
<a class="zoom first" data-rel="lightbox[product-gallery]" title="1422571167-808" href="MY WEBSITE/... .jpg">
<img class="attachment-shop_thumbnail" width="58" height="58" alt="1422571167-808" src="MY WEBSITE/...-58x58.jpg">
</a>

谢谢你在这里寻求解决方案!

0 个答案:

没有答案