Skip to content

Instantly share code, notes, and snippets.

@chris-jamieson
Created June 15, 2014 21:43
Show Gist options
  • Save chris-jamieson/f762dd9c82e00699bb43 to your computer and use it in GitHub Desktop.
Save chris-jamieson/f762dd9c82e00699bb43 to your computer and use it in GitHub Desktop.
Drupal commerce hide billing address fields when giftcard added to make order free
/**
* function to remove billing fields from display if giftcard / coupon makes order total £0.00
*/
$(document).ready(function(){
// on change due to ajax
$( document ).ajaxComplete(function() {
console.log( "Triggered ajaxComplete handler." );
var orderTotal = $('.page-checkout .view-id-commerce_cart_summary .field-name-commerce-order-total .component-type-commerce-price-formatted-amount .component-total').text();
if(orderTotal == '£0.00'){
console.log('Order total is zero (var: ' + orderTotal + ')');
// hide the .field-name-commerce-customer-address container contents
$('.form-item-customer-profile-billing-commerce-customer-address-und-0-country').hide(); // this will have a default value anyway
$('.street-block, .locality-block').hide();
// set all fields in .field-name-commerce-customer-address to value = 'Free order - no billing details needed'
if( !$('input.thoroughfare').val() ) { // because it might be pre-filled from a previous order
$('input.thoroughfare').val('Free order - no info required');
}
if( !$('input.locality').val() ) { // because it might be pre-filled from a previous order
$('input.locality').val('Free order - no info required');
}
if( !$('input.postal-code').val() ) { // because it might be pre-filled from a previous order
$('input.postal-code').val('E8 3PH'); // bakery address
}
// @TODO replace it with some text like "Free order - no billing information required"
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment