CHECKOUT shipping edits

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

function wpd_cehckout_shipping_edits() {
	?>
<script>
	jQuery(document).ready(function ($) {
		jQuery(document).ready(function () { // this is on purpose
			if ($('.woocommerce-shipping-totals').length) {
				const $showAllButton = $('<a/>', {
					id: "shipping-point",
					class: 'show-all-btn',
					href: '#'
				});
				$showAllButton.text('Change shipping');
				$showAllButton.on('click', function(ev) {
					ev.preventDefault();
					
					$('#shipping_method li').fadeIn();
					$(this).fadeOut();
				});
				
				$showAllButton.hide();
				
				$('body').on('updated_checkout', function () {
					const $after = $('.woocommerce-shipping-totals').next();
					const $checkedInputLi = $('#shipping_method input:checked').parent();
					
					if ($after.length) {
						const $table = $('<table>');
						$table.append($after);

						$checkedInputLi.append($table);
					}

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

<script>

jQuery(document).on('updated_checkout',function() {
	jQuery(".shipping_method").parent().on('click', function(){
		jQuery(this).children("label")[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 shipping at the checkout.

Author

Tags