I can't get it to work with woocommerce, card completely disappears after the page is loaded
I've just grabbed card jquery version and implemented it on my woocommerce powered website. For now I'm developing on localhost so I can't leave a live link to the website here.
Anyway, I can state it works because when the page is loading I'm able to see the card is also loading in place, right where the <div class="card-wrapper"></div> is placed. However, after the page has finished loading it suddenly disappears, and all the card stuff is completely gone from within the wrapper.
I see no js erros in chrome's console, so this leads me to think it might be something related to the way woocommerce deals with payment options, because I want card to override a third party credit card payment method credit card fields. Everything related to woocommerce's checkout form is wrapped on a form with the class .checkout, this also includes the credit card fields that belongs to a third party payment method plugin.
The credit card fields from the third party plugin are very basic, please see the plugin's screenshots https://br.wordpress.org/plugins/cielo-woocommerce/screenshots/
I'm initiating the plugin like the follow, where "checkout" is the actual woocommerce's checkout form class. I've also replaced the form selectors to the actual credit card fields ids.
jQuery('.checkout').card({
// a selector or DOM element for the container
// where you want the card to appear
container: '.card-wrapper', // *required*
formSelectors: {
numberInput: 'input#cielo-card-number', // optional — default input[name="number"]
expiryInput: 'input#cielo-card-expiry', // optional — default input[name="expiry"]
cvcInput: 'input#cielo-card-cvc', // optional — default input[name="cvc"]
nameInput: 'input#cielo-card-holder-name' // optional - defaults input[name="name"]
},
});
Woocommerce seems to deal with js to manage the payment method options, it usually uses radio fields that conditionally displays the selected payment method hiding all the other stuff from the sight. Not sure if that's related to the issue I'm describing here but I'd be great if someone who has integrated it within woocommerce could point me the right direction.
Thanks in advance for your time.
This seems like a WooCommerce specific issue. Someone here may be able to help you.
Did you ever figure this out? I would like to implement Card on our woo based store too!
I ended up setting up a custom style for the form of the payment method plugin I use. Here's the result: https://github.com/greguly/cielo-woocommerce/issues/36#issuecomment-244795738
I haven't tested it, but the issue seems to be related to how WooCommerce checkout.js deals with refreshing the page and the form contents. When one fills a field or checks a payment method option, WooCommerce refreshes the page form for validation and other logic purposes.
I'm not sure though, but one would need to hook into WooCommerce’s checkout js events in order to reinit card.js, I haven't tested it, but something like the trigger update_checkout should work:
$(document.body).on('updated_checkout', function(){
$('form').card({
container: '.card-wrapper', // *required*
});
});
That's work for me! Thanks!
If anyone is interested... I figured out that there's some sort of limitation where it needs to be attached to a form and not just any element (fieldset) so the workaround is:
- create a simple form in your payment gateway
- add fields inside the form
- add hidden fields outside the form
- on submit copy fields to hidden field which actually get sent over
done ez pz lemon squeezy
@RodrigoTorresWeb managed to implement in WooCommerce? If you did, can you help us by mentioning here how you did it?
@RodrigoTorresWeb I'm almost done, but in my code it only shows the skin of Hipercard and Troy, the other cards are just gray ;(