|
21 | 21 | var button_settings = {
|
22 | 22 | // set checkout environment
|
23 | 23 | merchantId: amazon_payments_advanced.merchant_id,
|
24 |
| - ledgerCurrency: 'EUR', // TODO: Implement multicurrency |
| 24 | + ledgerCurrency: amazon_payments_advanced.ledger_currency, |
25 | 25 | sandbox: amazon_payments_advanced.sandbox === '1' ? true : false,
|
26 | 26 | // customize the buyer experience
|
27 | 27 | productType: amazon_payments_advanced.action,
|
|
49 | 49 | }
|
50 | 50 |
|
51 | 51 | function activateChange( button_id, action ) {
|
52 |
| - if ( 0 === $( button_id ).length ) { |
| 52 | + var $btn = $( button_id ); |
| 53 | + if ( 0 === $btn.length || $btn.data( 'wc_apa_chage_bind' ) === action ) { |
53 | 54 | return;
|
54 | 55 | }
|
55 |
| - $( button_id ).on( 'click', function( e ) { |
| 56 | + $btn.data( 'wc_apa_chage_bind', action ); |
| 57 | + $btn.on( 'click', function( e ) { |
56 | 58 | e.preventDefault();
|
57 | 59 | } );
|
58 | 60 | amazon.Pay.bindChangeAction( button_id, {
|
|
77 | 79 | }
|
78 | 80 |
|
79 | 81 | function initAmazonPaymentFields() {
|
| 82 | + if ( ! isAmazonCheckout() ) { |
| 83 | + return; |
| 84 | + } |
80 | 85 | toggleDetailsVisibility( 'woocommerce-billing-fields' );
|
81 | 86 | toggleDetailsVisibility( 'woocommerce-shipping-fields' );
|
82 | 87 | toggleDetailsVisibility( 'woocommerce-additional-fields' );
|
83 | 88 | activateChange( '#payment_method_widget_change', 'changePayment' );
|
84 | 89 | activateChange( '#shipping_address_widget_change', 'changeAddress' );
|
85 |
| - } |
86 | 90 |
|
87 |
| - $( 'body' ).on( 'updated_checkout', function() { |
88 |
| - initAmazonPaymentFields(); |
89 |
| - if ( ! isAmazonCheckout() ) { |
90 |
| - return; |
91 |
| - } |
92 | 91 | if ( $( '.woocommerce-billing-fields .woocommerce-billing-fields__field-wrapper > *' ).length > 0 ) {
|
93 | 92 | $( '.woocommerce-billing-fields' ).insertBefore( '#payment' );
|
94 | 93 | }
|
| 94 | + |
| 95 | + if ( $( '.woocommerce-account-fields' ).length > 0 ) { |
| 96 | + $( '.woocommerce-account-fields' ).insertBefore( '#wc-apa-account-fields-anchor' ); |
| 97 | + } |
| 98 | + |
95 | 99 | if ( $( '.woocommerce-shipping-fields .woocommerce-shipping-fields__field-wrapper > *' ).length > 0 ) {
|
96 | 100 | var title = $( '#ship-to-different-address' );
|
97 | 101 | title.find( ':checkbox#ship-to-different-address-checkbox' ).hide();
|
98 | 102 | title.find( 'span' ).text( amazon_payments_advanced.shipping_title );
|
99 | 103 | $( '.woocommerce-shipping-fields' ).insertBefore( '#payment' );
|
100 | 104 | }
|
101 | 105 | $( '.woocommerce-additional-fields' ).insertBefore( '#payment' );
|
102 |
| - } ); |
| 106 | + } |
| 107 | + |
| 108 | + initAmazonPaymentFields(); |
| 109 | + |
| 110 | + $( 'body' ).on( 'updated_checkout', initAmazonPaymentFields ); |
103 | 111 | } );
|
104 | 112 | } )( jQuery );
|
0 commit comments