在 woocommerce 中更改标题 "Additional Information"

Change title "Additional Information" in woocommerce

我想从结帐页面更改标题。但我只能更改标签和占位符。

// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['order']['order_comments']['placeholder'] = 'Please type your PO number here and we will add it to the invoice.';
     $fields['order']['order_comments']['label'] = '';
     return $fields;
}

目前还没有更改章节标题的钩子。但是,如果您迫不及待地想进行修改,这就是破解方法。

  1. 找到您的模板文件夹
  2. 创建一个名为 'checkout'
  3. 的文件夹
  4. 在 templates/checkout/
  5. 下的 Woocommerce 插件文件夹中找到文件 form-shipping.php
  6. 将步骤 3 中的文件复制到步骤 2 中创建的文件夹中
  7. 现在您对结帐表单拥有超能力

编辑这一行:

<h3><?php _e( 'Additional Information', 'woocommerce' ); ?></h3>

如果有人仍在进行此更改,这对我有用

//Shipping Weight custom tab name

add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
function woo_rename_tabs( $tabs ) {

    $tabs['additional_information']['title'] = __( 'Additional Information' );  // Rename the Additional Information text
    return $tabs;

}
function th_wc_order_review_strings( $translated_text, $text, $domain ) {

  if(is_checkout()){
    switch ($translated_text) {
      case 'Billing details' :
        $translated_text = __( 'Billing Info', 'woocommerce' );
        break;
      case 'Additional information':
        $translated_text = __('New Field Name', 'woocommerce');
        break;
     case 'Your order':
        $translated_text = __('My Order', 'woocommerce');
        break;
     case 'Product':
        $translated_text = __('Your Product', 'woocommerce');
        break;
    }
  }
  return $translated_text;
}
add_filter( 'gettext', 'th_wc_order_review_strings', 20, 3 );

这个解决方案对我有用:

function ajg_relabel_additional_information_tab(){
    return __( 'Specification', 'text-domain' );
}
add_filter('woocommerce_product_additional_information_heading', 'ajg_relabel_additional_information_tab');

https://docs.woocommerce.com/document/editing-product-data-tabs/#

/**
 * Rename product data tabs
 */
add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );

function woo_rename_tabs( $tabs ) {
    $tabs['description']['title'] = __( 'More Information' );            // Rename the description tab
    $tabs['reviews']['title'] = __( 'Ratings' );                         // Rename the reviews tab
    $tabs['additional_information']['title'] = __( 'Product Data' );     // Rename the additional information tab

    return $tabs;
}

Woocommerce 的文档不完整...

https://docs.woocommerce.com/document/editing-product-data-tabs/

在添加或替换数组中的某些值之前,您将检查有关回调的条件,否则选项卡将显示里面没有任何内容。

/**
 * Filter product data tabs
 */
function filter_product_tabs( $tabs ) {

    global $product;

    if ( isset($tabs['description']['callback']) ) {
        $tabs['description']['title'] = __( 'More Information' );            // Rename the description tab
        $tabs['description']['priority'] = 5;           // Description
    }

    if ( isset($tabs['additional_information']['callback']) ) {
        $tabs['additional_information']['title'] = __( 'Product Data' );     // Rename the additional information tab
        $tabs['additional_information']['priority'] = 10;   // Additional information
    }

    if ( isset($tabs['reviews']['callback']) ) {
        $tabs['reviews']['title'] = __( 'Review' ) . ' (' . $product->get_review_count() . ') ';  // Rename the reviews tab
        $tabs['reviews']['priority'] = 15;          // Reviews
    }

    return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'filter_product_tabs', 98 );

为什么?因为开发人员 Woocommerce 将检查选项卡模板中数组的内容 (版本 3.8.0)(WC

/**
 * Filter tabs and allow third parties to add their own.
 *
 * Each tab is an array containing title, callback and priority.
 *
 * @see woocommerce_default_product_tabs()
 */

$product_tabs = apply_filters( 'woocommerce_product_tabs', array() );
    
    if ( ! empty( $product_tabs ) ) : 

....