-שנית, עשיתי תנאי עם jq שכש ה id של משלוח פעיל, תופיע השורה ״דמי משלוח כלולים״ וכשה id של איסוף עצמי פעיל, תופיע השורה ״ללא דמי משלוח״קוד עגלה אריה
Tue Feb 27 2024 12:22:11 GMT+0000 (Coordinated Universal Time)
Saved by
@odesign
add_action( 'woocommerce_proceed_to_checkout', 'add_custom_lines_above_checkout_button', 5 );
function add_custom_lines_above_checkout_button() {
echo '<p class="custom-line-above-checkout">לא כולל דמי משלוח</p>';
echo '<p class="second-custom-line-above-checkout" style="display:none;">דמי משלוח כלולים</p>';
}
add_action( 'wp_footer', 'custom_checkout_js' );
function custom_checkout_js() {
?>
<script>
jQuery(document).ready(function($) {
// Check if the radio button is checked initially
if ($('#shipping_method_0_flat_rate4').is(':checked')) {
$('.custom-line-above-checkout').hide(); // Hide the first element initially
$('.second-custom-line-above-checkout').show(); // Show the second element initially
}
// Add change event listener to the radio button
$('input[type="radio"][name="shipping_method"]').change(function() {
// Check if the radio button with ID shipping_method_0_flat_rate4 is checked
if ($(this).attr('id') === 'shipping_method_0_flat_rate4' && $(this).is(':checked')) {
$('.custom-line-above-checkout').hide(); // Hide the first element
$('.second-custom-line-above-checkout').show(); // Show the second element
} else {
$('.custom-line-above-checkout').show(); // Show the first element
$('.second-custom-line-above-checkout').hide(); // Hide the second element
}
});
});
</script>
<?php
}
content_copyCOPY
Comments