• Resolved Colin

    (@colinsafranek)


    Thank you for this plugin! It is very handy.

    I am trying to modify the error text by using the gettext filter. I took a look in your plugin’s main file and found your text domain to be: ‘woocommerce-product-dependencies’, is that correct?

    I’ve copy/pasted the exact error text I want to modify, but the gettext filter is not catching and translating properly. I already have it successfully translating multiple other WooCommerce text strings, so I know the filter is setup properly. It just isn’t working for your plugin’s error text :-/

    Can you please take a look at my code and tell me how I can fix it?

    function wuwo_gettext_woocommerce_replacements( $translated_text, $text, $text_domain )
    {
    	// bail if not modifying frontend woocommerce text
    	if (
            is_admin()
            || 'woocommerce' !== $text_domain
            || 'woocommerce-product-dependencies' !== $text_domain
        )
    	{
    		return $translated_text;
    	}
    
    	switch ( $translated_text )
    	{
    		case 'Coupon code applied successfully.' :
    			$translated_text = __( 'Discount applied successfully.', 'woocommerce' );
    			break;
    
    		case 'Apply Coupon' :
    			$translated_text = __( 'Apply Discount Code', 'woocommerce' );
    			break;
    
    		case 'Sale!' :
    			$translated_text = __( 'Discounted!', 'woocommerce' );
    			break;
    
            case 'Customer details' :
                $translated_text = __( 'Your Details', 'woocommerce');
                break;
    
            case 'Customer Details' :
                $translated_text = __( 'Your Details', 'woocommerce');
                break;
    
            case 'Access to "Competitor" is restricted only to verified owners of "Gym". Alternatively, access to this item will be granted after adding a "Gym" to the cart.' :
                $translated_text = __( 'The Competitor track is an add-on product for the Gym session plans. It cannot be purchased alone.', 'woocommerce-product-dependencies' );
                break;
    
            case 'Access to "Oly" is restricted only to verified owners of "Gym". Alternatively, access to this item will be granted after adding a "Gym" to the cart.' :
                $oly_alone       = wc_get_product_id_by_sku( 'WUWOolyalone_apex' );
                $oly_cart_url    = esc_url_raw( add_query_arg( 'add-to-cart', $oly_alone, wc_get_cart_url() ) );
                $translated_text = __( 'The Oly track is meant to be used with the Gym session plans. If you want to purchase the Oly track by itself <a href="' . $oly_cart_url . '" title="add Oly to your cart">click here</a>.', 'woocommerce-product-dependencies' );
                break;
    	}
    
    	return $translated_text;
    }
    add_filter( 'gettext', 'wuwo_gettext_woocommerce_replacements', 10, 3 );

    Your help is MUCH appreciated!!

    Cheers,
    – Colin

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Colin

    (@colinsafranek)

    bump

    Plugin Author SomewhereWarm

    (@somewherewarm)

    Hey @colin

    Apologies for the delay ??

    I am not sure what you are trying to achieve with this code, but if you want to localize or modify a WP plugin string you could create a translation using PoEdit or perhaps a plugin such as Loco Translate.

    Using gettext filters to do this is a tedious, slow approach that’t not portable at all.

    Is there a reason why you can’t use po/mo files?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘gettext filter, text domain’ is closed to new replies.