diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 2a0eb58..20ecd9e 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,3 +1,15 @@ +## 1.7.4 + +* Remove empty fields form fields + +## 1.7.3 + +* Add element container for extra fields, to deal with Cartflows + +## 1.7.2 + +* Adjustment for Cartflows + ## 1.7.1 * Version fix, last release got 0.0.0-development as release number diff --git a/assets/js/ledyer-checkout-for-woocommerce.js b/assets/js/ledyer-checkout-for-woocommerce.js index 0485b1a..6dd7543 100644 --- a/assets/js/ledyer-checkout-for-woocommerce.js +++ b/assets/js/ledyer-checkout-for-woocommerce.js @@ -189,7 +189,7 @@ jQuery(function ($) { type: 'POST', url: lco_params.update_cart_url, data: { - checkout: $('form.checkout').serialize(), + checkout: lco_wc.cleanupForm($('form.checkout')), nonce: lco_params.update_cart_nonce }, dataType: 'json', @@ -356,6 +356,17 @@ jQuery(function ($) { }, 1000); }, + cleanupForm: function (formElement) { + const $inputs = formElement.find('input, select, textarea'); + // remove inputs with empty values + const $inputsWithValue = $inputs.filter(function() { + return $(this).val() !== ""; + }); + const serializedData = $inputsWithValue.serialize(); + + return serializedData; + }, + /** * Places the Ledyer order * @param {string} should_validate @@ -377,7 +388,7 @@ jQuery(function ($) { $.ajax({ type: 'POST', url: lco_params.submit_order, - data: $('form.checkout').serialize(), + data: lco_wc.cleanupForm($('form.checkout')), dataType: 'json', success: function (data) { // data is an object with the following properties: @@ -393,8 +404,8 @@ jQuery(function ($) { shouldProceed: true }) // Ledyer will respond with a new event when order is complete - // So don't redirect just yet, - // eventually redirection will happen in ledyerCheckoutOrderComplete + // So don't redirect just yet, + // eventually redirection will happen in ledyerCheckoutOrderComplete return; } window.location.href = url.toString(); diff --git a/classes/class-ledyer-main.php b/classes/class-ledyer-main.php index 5dae864..f8d564f 100644 --- a/classes/class-ledyer-main.php +++ b/classes/class-ledyer-main.php @@ -51,7 +51,7 @@ class Ledyer_Checkout_For_WooCommerce { */ public $checkout; - const VERSION = '0.0.0-development'; + const VERSION = '1.7.4'; const SLUG = 'ledyer-checkout-for-woocommerce'; const SETTINGS = 'ledyer_checkout_for_woocommerce_settings'; @@ -351,6 +351,12 @@ public function modify_checkout_fields( $checkout_fields ) { $checkout_fields['shipping'][ $key ]['required'] = false; } } + + $checkout_fields['billing']['lco_shipping_data'] = array( + 'type' => 'hidden', + 'class' => array( 'lco_shipping_data' ), + 'default' => '', + ); } return $checkout_fields; diff --git a/classes/class-ledyer-templates.php b/classes/class-ledyer-templates.php index d9c4fea..86fd27d 100644 --- a/classes/class-ledyer-templates.php +++ b/classes/class-ledyer-templates.php @@ -34,6 +34,7 @@ public function actions() { \add_action( 'wp_footer', array( $this, 'check_that_lco_template_has_loaded' ) ); // Template hooks. + add_action( 'lco_wc_after_order_review', 'lco_wc_add_extra_checkout_fields', 10 ); add_action( 'lco_wc_after_order_review', 'lco_wc_show_another_gateway_button', 20 ); add_action( 'lco_wc_before_snippet', array( $this, 'add_wc_form' ), 10 ); } diff --git a/includes/lco-functions.php b/includes/lco-functions.php index 1c15a23..7a57f45 100644 --- a/includes/lco-functions.php +++ b/includes/lco-functions.php @@ -164,6 +164,20 @@ function lco_wc_show_another_gateway_button() { } } +/** + * Adds the extra checkout field div to the checkout page. + * + * @return void + */ +function lco_wc_add_extra_checkout_fields() { + do_action( 'lco_wc_before_extra_fields' ); + ?> +
+
+