首页 > 解决方案 > 从 Woocommerce 3rd 方插件更改文本

问题描述

我正在使用 WooCommerce Wishlist 并希望将产品添加到其他产品中。这是片段:

public static function add_to_wishlist_button( $url, $product_type, $exists ) {
    _deprecated_function( 'add_to_wishlist_button', '2.0.0', 'add-to-wishlist-button.php template' );
    global $yith_wcwl, $product;
    $product_id = yit_get_product_id( $product );
    $label_option = get_option( 'yith_wcwl_add_to_wishlist_text' );
    $localize_label = function_exists( 'icl_translate' ) ? icl_translate( 'Plugins', 'plugin_yit_wishlist_button', $label_option ) : $label_option;
    $label = apply_filters( 'yith_wcwl_button_label', $localize_label );
    $icon = get_option( 'yith_wcwl_add_to_wishlist_icon' ) != 'none' ? '<i class="fa ' . get_option( 'yith_wcwl_add_to_wishlist_icon' ) . '"></i>' : '';
    $classes = get_option( 'yith_wcwl_use_button' ) == 'yes' ? 'class="add_to_wishlist single_add_to_wishlist button alt"' : 'class="add_to_wishlist"';
    $html  = '<div class="yith-wcwl-add-to-wishlist">';
    $html .= '<div class="yith-wcwl-add-button';  // the class attribute is closed in the next row
    $html .= $exists ? ' hide" style="display:none;"' : ' show"';
    $html .= '><a href="' . esc_url( add_query_arg( 'add_to_wishlist', $product_id ) ) . '" data-product-id="' . $product_id . '" data-product-type="' . $product_type . '" ' . $classes . ' >' . $icon . $label . '</a>';
    $html .= '<img src="' . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . '" class="ajax-loading" alt="loading" width="16" height="16" style="visibility:hidden" />';
    $html .= '</div>';
    $html .= '<div class="yith-wcwl-wishlistaddedbrowse hide" style="display:none;"><span class="feedback">' . __( 'Product added!','yith-woocommerce-wishlist' ) . '</span> <a href="' . esc_url( $url ) . '">' . apply_filters( 'yith-wcwl-browse-wishlist-label', __( 'Browse Wishlist', 'yith-woocommerce-wishlist' ) ) . '</a></div>';
    $html .= '<div class="yith-wcwl-wishlistexistsbrowse ' . ( $exists ? 'show' : 'hide' ) . '" style="display:' . ( $exists ? 'block' : 'none' ) . '"><span class="feedback">' . __( 'The product is already in the wishlist!', 'yith-woocommerce-wishlist' ) . '</span> <a href="' . esc_url( $url ) . '">' . apply_filters( 'yith-wcwl-browse-wishlist-label', __( 'Browse Wishlist', 'yith-woocommerce-wishlist' ) ) . '</a></div>';
    $html .= '<div style="clear:both"></div><div class="yith-wcwl-wishlistaddresponse"></div>';
    $html .= '</div>';
    $html .= '<div class="clear"></div>';
    return $html;
}

从 function.php 更改该文本的最佳做法是什么

标签: phpwordpresswoocommercegettext

解决方案


由于字符串已经被包装到函数__($string, $domain)中,您可以轻松地翻译它,而无需使用任何代码或编辑您的functions.php。您只需要一个翻译插件(我建议使用 Loco Translate)。

  • 安装插件
  • 安装后,使用 WP 仪表板上的左栏菜单转到“Loco Translate”>“Plugins”
  • 您将看到当前安装在您网站上的插件列表,选择您用于管理 WooCommerce Whislists 的插件列表
  • 然后从列表中选择您的语言,如果您的语言不存在,则单击“新语言”(如果您正在创建新语言,请插入语言设置)
  • 选择您要翻译的字符串,并将翻译放在底部的文本区域
  • 节省

推荐阅读