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

Read More

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;
})();

Related posts

Leave a Reply

1 comment