Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom checkout button markup can cause a JS error when clicked. #8834

Closed
cklosowski opened this issue Aug 25, 2021 · 5 comments · Fixed by #8850
Closed

Custom checkout button markup can cause a JS error when clicked. #8834

cklosowski opened this issue Aug 25, 2021 · 5 comments · Fixed by #8850
Assignees
Labels
component-checkout type-regression Something that used to work that doesn't anymore
Milestone

Comments

@cklosowski
Copy link
Contributor

Bug Report

Expected behavior

When I customize my checkout button, I expect it to work still when clicked.

Actual behavior

Due to these changes in the edd-ajax.js file https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/assets/js/edd-ajax.js#L402-L405, a customized checkout button will not have the attribute, and therefore possibly fail.

Steps to reproduce the behavior

  1. Customize your checkout button markup.
  2. Try and checkout.

Information (if a specific version is affected):

PHP Version: All

EDD Version (or branch): 2.11

WordPress Version: All

Any other relevant information:

@cklosowski cklosowski added this to the 2.11.1 milestone Aug 25, 2021
@cklosowski cklosowski self-assigned this Aug 25, 2021
@cklosowski cklosowski added type-regression Something that used to work that doesn't anymore and removed type-bug labels Aug 25, 2021
@cklosowski
Copy link
Contributor Author

So this issue was caused by the edd-ajax.js file now requiring that the checkout button has an ID attribute of edd-purchase-button. That has never been required prior to this. The default button has had the ID since 2012, so it's pretty safe to assume it's there, but if anyone else sees this, the fix is to add the id="edd-purchase-button" attribute to your custom checkout button.

@cklosowski cklosowski removed this from the 2.11.1 milestone Aug 25, 2021
@cklosowski
Copy link
Contributor Author

Some feedback:

Based on the JS in edd-ajax.js, it shouldn't even be necessary to set the
submit button to a variable since it should already be accessible via
'this'.

Simply making this change *should* enable the new button behavior without
breaking existing custom buttons that lack id attributes.

@cklosowski cklosowski reopened this Aug 25, 2021
@cklosowski
Copy link
Contributor Author

going to re-open to see if this is something we can take as an approach for backwards compatibility and to reduce that technical debit of specific attributes here.

@ashleyfae
Copy link
Contributor

I don't think this change requires a specific ID, it just requires any ID.

But the feedback should be correct. I think we should be able to remove this line completely: https://github.com/easydigitaldownloads/easy-digital-downloads/blob/master/assets/js/edd-ajax.js#L402

and change this line to:

$(this).attr('data-original-value', complete_purchase_val);

@cklosowski
Copy link
Contributor Author

cklosowski commented Sep 7, 2021

Steps to replicate:

  1. Add this to an mu plugin:
function ck_custom_purchase_button( $button_markup ) {
	$button_markup = '<input type="submit" class="edd-submit green button" name="edd-purchase" value="Complete Checkout"/>';
	return $button_markup;
}
add_filter( 'edd_checkout_button_purchase', 'ck_custom_purchase_button', 9999, 1 );
  1. Go to the checkout and see the green button
  2. Attempt to checkout with Stripe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-checkout type-regression Something that used to work that doesn't anymore
Projects
None yet
2 participants