I'm trying to modify the Billing and Shipping text in the Order Details page, in my admin panel. (Screenshot)
I know, I can achieve this by editing the "class-wc-meta-box-order-data.php" file in the following directory & I was successful but know my changes will disappear after the update.
File location:
wp-content/plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-order-data.php
The Billing text is located on 312 Line & the Shipping Text is located on 428 Line.
I want to replace Billing with Sender Information
Shipping will be replaced with Recipient Information
I've tried using the following code & It worked, but I want to replace these words on the Order Details page only, in the admin panel, but this code is replacing these words on the frontend as well & I just want to update these words in the admin panel.
add_filter('gettext', 'translate_reply');
add_filter('ngettext', 'translate_reply');
function translate_reply($translated) {
$translated = str_ireplace('Shipping', 'Recipient Information',
$translated);
$translated = str_ireplace('Billing', 'Sender Information', $translated);
return $translated;
}
I've also tried placing the file directory in my child theme (after editing it), but it didn't work.
The following will only target Admin single "edit" (and "new") order pages:
add_filter( 'gettext', 'change_admin_single_order_heading3', 10, 3 );
add_filter( 'ngettext', 'change_admin_single_order_heading3', 10, 3 );
function change_admin_single_order_heading3( $translated, $text, $domain ) {
global $pagenow;
if ( is_admin() && ( ( $pagenow === 'post.php' && isset($_GET['post']) && get_post_type($_GET['post']) === 'shop_order' )
|| ( $pagenow === 'post-new.php' && isset($_GET['post-type']) && $_GET['post-type'] === 'shop_order' ) ) ) {
if( $text === 'Billing' && $domain === 'woocommerce' ){
$translated = esc_html__( 'Sender Information', $domain );
}
if( $text === 'Shipping' && $domain === 'woocommerce' ){
$translated = esc_html__( 'Recipient Information', $domain );
}
// Addition asked in your comment
if( $text === 'Shipping:' && $domain === 'woocommerce' ){
$translated = esc_html__( 'Some text', $domain );
}
}
return $translated;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.