Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
})();
like image 352
Andreas Øby Kjeldsen Avatar asked Nov 02 '22 01:11

Andreas Øby Kjeldsen


1 Answers

Andreas! Did you try this?

$('.variations_form').trigger('check_variations');
like image 135
Artem Lapkin Avatar answered Nov 10 '22 00:11

Artem Lapkin