mercredi 20 avril 2016

Woocommerce change order total on dropdown change

I have a plugin in woocommerce that adds a credit card payment method. I customized the plugin and I added a dropdown as a payment field in which the customer can choose istallments. The installments have an interest rate so I want everytime that the customer chooses the number of installments he wants it will update the orders total accordingly. I have used a piece of code that includes a jquery and ajax that posts the value of the dropdown... while the checkout field later updates normaly the price doesn't change cause the $_POST parameter doesn't seem to get any values. The ajax and the php functions are in the same file don't know if that has to do anything. Here is the jquery:

jQuery(document).ready(function () {

jQuery('#installments').change(function () {
    var billing_district = jQuery('#installments').val();
    console.log(installments);
    var data = {
        action: 'woocommerce-nbg-payment-gateway',
        security: wc_checkout_params.apply_district_nonce,
        district: billing_district
    };

    jQuery.ajax({
        type: 'POST',
        url: wc_checkout_params.ajax_url,
        data: data,
        success: function (code) {
            console.log(code);
            if (code === '0') {
                //$form.before(code);
                jQuery('body').trigger('update_checkout');

            }
        },
        dataType: 'html'
    });

    return false;
});

});

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire