Customizing WooCommerce Short Description Metabox title

血红的双手。 提交于 2020-06-27 04:44:10

问题


Can someone guide me by telling me how I can customize/change Text label in Wordpress - I recently installed WooCommerce on my wordpress, and need to change the label "Product Short Description" on the "Add Product" page to something else. Is there a way to getting this done? Please see this image for reference: screenshot


回答1:


To answer to your question: YES there is a working filter hook that can translate text by the internationalization functions (__(), _e(), etc.)

Here is this code:

add_filter( 'gettext', 'theme_domain_change_excerpt_label', 10, 2 );
function theme_domain_change_excerpt_label( $translation, $original )
{
    if ( 'Product Short Description' == $original ) {
        return 'My Product label';
    }
    return $translation;
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and fully functional.


References:
  • gettext
  • Change The Title Of a Meta Box



回答2:


Borrowing from here

The basic premise is that you remove the existing metabox and then add it back with a new title, but the same callback, which (as it happens) is similar to what WooCommerce did with the usual "excerpt" metabox. :

remove_meta_box( 'METABOX_ID', 'POST_TYPE', 'normal' );
add_meta_box('METABOX_ID', __('META BOX TITLE'), 'METABOX_CALLBACK', 'POST_TYPE', 'normal', 'high');

So in this case you'd want to do the following:

add_action( 'add_meta_boxes', 'so_39797888_rename_meta_boxes', 40 );
function so_39797888_rename_meta_boxes(){
    remove_meta_box( 'postexcerpt', 'product', 'normal' );
    add_meta_box( 'postexcerpt', __( 'This metabox is awesome', 'your-plugin' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
}

You need to be on a priority of 40 so that your function will come after WooCommerce has added it's metabox.



来源:https://stackoverflow.com/questions/39797888/customizing-woocommerce-short-description-metabox-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!