I’m using WooCommerce Wishlist and want to change product added to something else.
here is the snippet:
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;
}
What is the best practice to change that text from function.php
2
Answers
Since the string is already wrapped into the function
__($string, $domain)
, you can easily translate it without using any code or editing your functions.php.All you need is a translator plugin (I suggest using Loco Translate).
I see you’ve already accepted an answer, but you asked about putting this into a function, so here’s how. Filter
gettext
accepts 3 parameters gettext HookMe personally… I would rather add a few lines of code than have an entire plugin (which probably adds scripts and css overhead to my site) to do what this little snippet can do.