简体   繁体   中英

Trigger check_variations event in Woocommerce

I'm trying to make a text based selection for my product variationon on my single product page. I basically generate a p-tag for every option in every variation and use javascript to select the option in the default Woocommerce select dropdown. The option gets selected fine but the check_variations event doesn't get triggered.

Does anyone know how to trigger the check_variations event from my theme? The check_variations listener is in woocommerce/assets/js/frontend/add-to-cart-variation.js

JS

var ProductVariations = (function () {
    function ProductVariations() {
        this.$variationClickables = $('.variations .value p');
        this.setupClickHandlers();
    }
    ProductVariations.prototype.setupClickHandlers = function () {
        var _this = this;
        this.$variationClickables.bind('click', function (event) {
            _this.variationsClicked(event);
        });
    };

    ProductVariations.prototype.variationsClicked = function (event) {
        var $target = $(event.target);
        var targetVariation = $target.attr('value');
        $('option[value=' + targetVariation + ']', $target.closest('.variations')).attr('selected', 'true');
        $target.closest('.variations_form').trigger('change');
    };
    return ProductVariations;
})();

Andreas! Did you try this?

$('.variations_form').trigger('check_variations');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM