CHECKOUT payment edits

0.0/5
<?php
add_action('wp_footer', 'wpd_checkout_payment_edits');

function wpd_checkout_payment_edits() {
	?>
<script>
	jQuery(document).ready(function ($) {
		jQuery(document).ready(function () { // this is on purpose
			if ($('.wc_payment_methods').length) {
				const $showAllButton = $('<a/>', {
					id: "payment-btn",
					class: 'show-all-btn',
					href: '#'
				});
				$showAllButton.text('Change payment method');
				$showAllButton.on('click', function(ev) {
					ev.preventDefault();
					
					$('#payment ul li').fadeIn();
					$(this).fadeOut();
				});
				
				$showAllButton.hide();
				
				$('body').on('updated_checkout', function () {
					const $checkedInputLi = $('#payment ul li input:checked').parent();

					if ($checkedInputLi.length) {
						let $button = $('#payment-btn');
						
						if (!$button.length) {
							$button = $showAllButton.clone(true, true);
							$button.insertAfter($('#payment ul'));
						}
						
						$('#payment ul li').not($checkedInputLi).fadeOut();
						$button.fadeIn();
					}
				});
			}
		});
	});
</script>

<script>
	/*jQuery(document).on('updated_checkout',function() {
		jQuery("li.payment_method_comgate").click(function() {
			jQuery("li.payment_method_comgate label")[0].click();
		})
	});

	jQuery(document).on('updated_checkout',function() {
		jQuery("li.payment_method_dobirka").click(function() {
			jQuery("li.payment_method_dobirka label")[0].click();
		})
	});

	jQuery(document).on('updated_checkout',function() {
		jQuery("li.payment_method_bacs").click(function() {
			jQuery("li.payment_method_bacs label")[0].click();
		})
	});*/

	jQuery(document).on('updated_checkout',function() {
	jQuery(".wc_payment_method").each(function(){
    let className = jQuery(this).attr("class").split(/s+/).find(element => element.startsWith("payment_method_"));
    jQuery(this).on('click', function(){
jQuery("label[for='" + className + "']")[0].click();
    });
});
	});
</script>
<?php
}

Comments and reviews

{{ reviewsTotal }} Review
{{ reviewsTotal }} Reviews
{{ options.labels.newReviewButton }}
{{ userData.canReview.message }}

Description

This snippet allows you to edit your payment at the checkout.

Author

Tags