Changing the label text (text only)
The text “Member discount!” can be changed using a translation filter, but it’s not possible to add an image or any HTML to that because it is escaped later in the code referenced in the question:
$badge="<span class="onsale wc-memberships-member-discount">" . esc_html( $label ) . '</span>';
Here is an example showing how to change the Member discount! text, but it will only work with text, not HTML:
add_filter( 'gettext', 'wpse244685_change_text', 20, 3 );
function wpse244685_change_text( $translated_text, $untranslated_text, $domain ) {
if ( 'woocommerce-memberships' !== $domain ) {
return $translated_text;
}
// make the changes to the text
switch( $untranslated_text ) {
case 'Member discount!' :
// $translated_text = __( 'New text', 'text_domain' ); // Example of new string
$translated_text=""; // Empty strings should not be translated
break;
// add more items
}
return $translated_text;
}
Adding an image or other HTML
Depending on how your product is configured, it looks like you can change the HTML for the badge, and therefore add an image, via either the wc_memberships_member_discount_badge
or wc_memberships_variation_member_discount_badge
filters as follows:
Standard Product:
add_filter( 'wc_memberships_member_discount_badge', 'wpse244685_wc_memberships_member_discount_badge', 10, 3 );
function wpse244685_wc_memberships_member_discount_badge( $badge, $the_post, $product ) {
$badge="<span class="onsale wc-memberships-member-discount">" .
'<img src="https://placekitten.com/300/300" alt="meow">' .
'</span>';
return $badge;
}
Variable Product:
add_filter( 'wc_memberships_variation_member_discount_badge', 'wpse244685_wc_memberships_variation_member_discount_badge', 10, 2 );
function wpse244685_wc_memberships_member_discount_badge( $badge, $product ) {
$badge="<span class="onsale wc-memberships-member-discount">" .
'<img src="https://placekitten.com/300/300" alt="meow">' .
'</span>';
return $badge;
}