Skip to content

Commit

Permalink
fix: add custom extra fields div (#87)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Solders <[email protected]>
  • Loading branch information
timjackleus and ssolders authored Oct 20, 2023
1 parent 1456c42 commit 4f1c06b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 15 additions & 4 deletions assets/js/ledyer-checkout-for-woocommerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion classes/class-ledyer-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions classes/class-ledyer-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
14 changes: 14 additions & 0 deletions includes/lco-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
?>
<div id="lco-extra-checkout-fields">
</div>
<?php
do_action( 'lco_wc_after_extra_fields' );
}

/**
* Confirm the order in WooCommerce.
*
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Contributors: maksimer, ledyer
Tags: woocommerce, ledyer, ecommerce, e-commerce, checkout
Donate link: https://ledyer.com
Requires at least: 4.0
Tested up to: 6.2
Tested up to: 6.3
Requires PHP: 7.0
WC requires at least: 4.0.0
WC tested up to: 6.9.3
WC tested up to: 8.2.0
Stable tag: 0.0.0-development
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

0 comments on commit 4f1c06b

Please sign in to comment.