Created
June 15, 2014 21:43
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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