Conditionally rename Shipping to different address? label woocommerce


I’m trying to rename the "Shipping to different address?" checkbox label when the "Sending as a gift" shipping method selected. First I’ve made the Shipping to default address checkbox checked, but I would like to rename it to "Gifted person’s address. Here are the code I’ve written. The default checking works, but the rename doesn’t. How can I achieve the rename and the checked state at once? Thank you very much.

add_action( 'init', 'fb_ship_to_open' );  
function fb_ship_to_open () {
  global $woocommerce;
    if ( !is_admin() && WC()->session->get( 'chosen_shipping_methods' ) ) {
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0]; 
      if ('foxpost_woo_parcel_home_delivery_shipping:7' == $chosen_shipping ) {
        add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' ); 

        function myscript() {
<script type="text/javascript">
    jQuery('#ship-to-different-address').find('span').html("Gifted person's address");
    jQuery('#order_comments_field').find('label').html("Write something kind..." <span class='optional'>(optional)</span>");
</script> }
add_action( 'wp_footer', 'myscript' );

      } else {
Ben 2 months 0 Answers 5 views 0

Leave an answer