Preview:
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
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter