Page 1 of 1

Coupon responses

PostPosted: December 26th, 2011, 12:24 pm
by jevans161
I would like to change the message that appears when someone apply a coupon to an s2member checkout page, how do I do that?

Re: Coupon responses

PostPosted: December 27th, 2011, 5:21 am
by Cristián Lávaque
That message comes from here viewtopic.php?f=40&t=13268&src_doc_v=110710#src_doc_line_401 but I don't see a hook you can use to customize it... You'd have to edit the source file, but it'll get overwritten the next time you update the plugin. This still needs to be improved. :|

Re: Coupon responses

PostPosted: December 27th, 2011, 9:23 pm
by jevans161
Is there a javascript workaround?

Re: Coupon responses

PostPosted: December 30th, 2011, 8:35 pm
by Jason Caldwell
Thanks for the heads up on this thread.

For anything like this that is NOT already implemented into s2Member's configurable interface, you can use contextual translation filters to modify the messages that s2Member displays.

All of s2Member's front-end messages are filterable using the gettext_with_context filter provided by the WordPress core.

Here is an example. Create this directory and file:
/wp-content/mu-plugins/s2-contextual-translation.php
( this is a MUST USE plugin, see: http://codex.wordpress.org/Must_Use_Plugins )
Code: Select all
<?php
add_filter
("gettext_with_context", "s2_contextual_translation", 10, 3);
function s2_contextual_translation($translation = NULL, $original = NULL, $context = NULL)
    {
        if($context === "s2member-front" && $original === "COUPON %s off. ( Now: %s )")
            /* Here you provide the translation.
            You can take the `%s` Replacement Codes out if needed. */
            $translation = "You received %s off. ( You now pay: %s )";
        /**/
        else if($context === "s2member-front" && $original === '<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s</strong> )</div>')
            $translation = '<div>You received: <strong>%s off</strong>. ( You now pay: <strong>%s</strong> )</div>';
        /**/
        else if($context === "s2member-front" && $original === "COUPON %s off. ( Now: %s, then %s )")
            $translation = "You received %s off. ( Now pay: %s, then %s )";
        /**/
        else if($context === "s2member-front" && $original === '<div>Coupon: <strong>%s off</strong>. ( Now: <strong>%s, then %s</strong> )</div>')
            $translation = '<div>You received: <strong>%s off</strong>. ( Now pay: <strong>%s, then %s</strong> )</div>';
        /**/
        return $translation;
    }
?>
s2-contextual-translation.zip
(553 Bytes) Downloaded 153 times

Re: Coupon responses

PostPosted: December 30th, 2011, 9:06 pm
by jevans161
Jason:

I tried this, and it didn't work. What am I doing wrong? I did not change the code in any way, and put it in the mu-plugins directory...

Thanks,

Jeffry

Re: Coupon responses

PostPosted: December 30th, 2011, 9:30 pm
by Jason Caldwell
Thanks for the follow-up Jeffry.
So sorry, there are actually two variations, one for plain text and another for HTML. I've updated to code sample above to account for all variations. See: viewtopic.php?f=4&t=16557&p=59282#p59282

Re: Coupon responses

PostPosted: December 30th, 2011, 9:59 pm
by jevans161
Awesome, I almost have it exactly the way I want it. The last thing I need to do is change the "for 1 month" that comes up. I want to keep the amount, but take those words off. This is the %s replacement code, is there way to change it?

Re: Coupon responses

PostPosted: December 30th, 2011, 10:22 pm
by Jason Caldwell
Yes, that is possible too. Leave the %s Replacement Code in your translation, and instead modify the underlying routine that drives that numeric value, using another filter for WordPress:
ngettext_with_context

Create this directory and file:
/wp-content/mu-plugins/s2-n-contextual-translation.php
Code: Select all
<?php
add_filter
('ngettext_with_context', 's2_n_contextual_translation', 10, 5);
function s2_n_contextual_translation($translated = NULL, $original_single = NULL, $original_plural = NULL, $number = NULL, $context = NULL)
    {
        if($context === 's2member-front' && $original_single === 'for %1$s %2$s')
            /* Ex: `good for 1 month`. Using `%1$s` and `%2$s`. */
            $translated = 'good for %1$s %2$s';
        /**/
        else if($context === 's2member-front' && $original_plural === 'for %1$s %3$s')
            /* Ex: `good for 2 months`. Using `%1$s` and `%3$s`. */
            $translated = 'good for %1$s %3$s';
        /**/
        return $translated;
    }
?>
s2-n-contextual-translation.zip
(461 Bytes) Downloaded 108 times

Re: Coupon responses

PostPosted: December 30th, 2011, 10:35 pm
by jevans161
Jason:

You are the man! I have it configured exactly the way I want now.

Thanks a million!

Jeffry

Re: Coupon responses

PostPosted: December 30th, 2011, 11:25 pm
by Jason Caldwell
Very welcome. Thanks for the KUDOS!