PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Coupon responses

Common Questions/Problems/Tips. Posted by Administrators & Support Reps.

Coupon responses

Postby jevans161 » December 26th, 2011, 12:24 pm

I would like to change the message that appears when someone apply a coupon to an s2member checkout page, how do I do that?
User avatar
jevans161
Registered User
Registered User
 
Posts: 16
Joined: October 29, 2011

Re: Coupon responses

Postby Cristián Lávaque » December 27th, 2011, 5:21 am

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. :|
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Coupon responses

Postby jevans161 » December 27th, 2011, 9:23 pm

Is there a javascript workaround?
User avatar
jevans161
Registered User
Registered User
 
Posts: 16
Joined: October 29, 2011

Re: Coupon responses

Postby Jason Caldwell » December 30th, 2011, 8:35 pm

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
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Coupon responses

Postby jevans161 » December 30th, 2011, 9:06 pm

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
User avatar
jevans161
Registered User
Registered User
 
Posts: 16
Joined: October 29, 2011

Re: Coupon responses

Postby Jason Caldwell » December 30th, 2011, 9:30 pm

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
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Coupon responses

Postby jevans161 » December 30th, 2011, 9:59 pm

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?
User avatar
jevans161
Registered User
Registered User
 
Posts: 16
Joined: October 29, 2011

Re: Coupon responses

Postby Jason Caldwell » December 30th, 2011, 10:22 pm

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
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Coupon responses

Postby jevans161 » December 30th, 2011, 10:35 pm

Jason:

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

Thanks a million!

Jeffry
User avatar
jevans161
Registered User
Registered User
 
Posts: 16
Joined: October 29, 2011

Re: Coupon responses

Postby Jason Caldwell » December 30th, 2011, 11:25 pm

Very welcome. Thanks for the KUDOS!
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA


Return to Common Questions/Problems/Tips

Who is online

Users browsing this forum: No registered users and 1 guest