skip to Main Content

Hi every one let me try to explain this.

PLEASE NOTE: i use the woo commerce block plugin (for the cart and checkout pages to replace the original shortcode)

i want to change my instances where the word shipping is to change to the word Delivery

i use this hook in my functions.php and it did change the one word to delivery so that worked

add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 );
function change_shipping_text_to_delivery( $sprintf, $i, $package ) {
    $sprintf = sprintf( _nx( 'Delivery', 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) );
    return $sprintf;
}

as you can see on the cart page it only changed the one word not the other two
enter image description here

okay then when i go to my PROCEED TO CHECKOUT AND GO TO THE PAGE

THIS IS MY CHECKOUT PAGE(also UNCHAGED)
enter image description here

i have insert this in my php functions did not work

/*
 *  Change the string "Shipping" to "Delivery" on Order Received page.
 */
add_filter('gettext', 'translate_reply');
add_filter('ngettext', 'translate_reply');

function translate_reply($translated) {
$translated = str_ireplace('Shipping', 'Delivery', $translated);
return $translated;
}

i also tried going to my plugin folder

i did get some code in there where i replaced the strings shipping to delviery and it did not do anything !

return (
        <FormStep
            id="shipping-fields"
            disabled={ checkoutIsProcessing }
            className="wc-block-checkout__shipping-fields"
            title={ __( 'Shipping address', 'woo-gutenberg-products-block' ) }
            description={ __(
                'Enter the physical address where you want us to deliver your order.',
                'woo-gutenberg-products-block'
            ) }
        >
            { children }
            <CheckboxControl
                className="wc-block-checkout__use-address-for-billing"
                label={ __(
                    'Use same address for billing',   
                    'woo-gutenberg-products-block'
                ) }
                checked={ shippingAsBilling }
                onChange={ ( isChecked ) => setShippingAsBilling( isChecked ) }
            />
        </FormStep>

Please can someone help me i just want to change those words to DELIVERY

2

Answers


  1. Chosen as BEST ANSWER

    i did come right with this code but i had to remove the woo commerce gutenberg block i reverted back to the default woo commerce shortcodes

    add_filter('woocommerce_shipping_package_name', 'change_shipping_text_to_delivery', 20, 3 );
    function change_shipping_text_to_delivery( $sprintf, $i, $package ) {
        $sprintf = sprintf( _nx( 'Delivery', 'Delivery %d', ( $i + 1 ), 'delivery packages', 'woocommerce' ), ( $i + 1 ) );
        return $sprintf;
    }function shipchange( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
    case 'Ship to a different address?' :
    $translated_text = __( 'Deliver to a different address?', 'woocommerce' );
    break;
    }
    return $translated_text;
    }
    
    add_filter('gettext', 'shipchange', 20, 3);
    
    add_filter( 'woocommerce_shipping_package_name' , 'woocommerce_replace_text_shipping_to_delivery', 10, 3);
    
    /**
     * 
     * Function to replace shipping text to delivery text
     * 
     * @param $package_name
     * @param $i
     * @param $package
     *
     * @return string
     */
    function woocommerce_replace_text_shipping_to_delivery($package_name, $i, $package){
        return sprintf( _nx( 'Delivery', 'Delivery %d', ( $i + 1 ), 'shipping packages', 'put-here-you-domain-i18n' ), ( $i + 1 ) );
    }
    
    /*
     *  Change the string "Shipping" to "Delivery" on Order Received page.
     */
    add_filter('gettext', 'translate_reply');
    add_filter('ngettext', 'translate_reply');
    
    function translate_reply($translated) {
    $translated = str_ireplace('Shipping', 'Delivery', $translated);
    return $translated;
    }
    

  2. Try something like below. This uses a filter hook to change the values in the $fields array. In your case, you are changing order details

     add_filter( 'woocommerce_checkout_fields' , 'your_function' );
        
        function your_function ( $fields ) {
             $fields['shipping']['shipping_address']['label'] = "Delivery Address";
             return $fields;
        }
    

    This would go in your functions.php file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search