Change the PayPal button in your TTG Cart

In the Cart settings you have two options for the PayPal button: Image and Text. If you choose Image, this is the PayPal button that will be used:

But what if you want something different, like this?

Well it’s pretty easy to change  out the PayPal button with just a little bit of jQuery code. But first, you’ll need to enable phplugins for the page template that you’ve assigned to the cart in Cart > Settings under Personalisation > Cart Template. Visit the TTG documentation for information on using phplugins.

The PayPal button used in Backlight is set to 36px in height, so you need to pick out a PayPal button that’s close to being that tall. All of them but the smallest should work. Take a look at this page for your choices. Click “Get Code” for the one you want.

What we’ll be doing is using jQuery to replace the html code that calls the button. I’ll provide the code below, you’ll just need to copy in the web address for the button you choose.
The code you get from Paypal will look like this:

<img src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/PP_logo_h_150x38.png" alt="PayPal" />

You just need the the part that starts with https and ends with .png.

Here is the code to add to your phplugin file:

function scripts(){
echo '
<script> 
$( "#cart-buttons form input" ).replaceWith( \'<input type="image" name="submit" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/cc-badges-ppmcvdam.png" alt="Pay with PayPal, PayPal Credit or any major credit card" border="0" align="top" width="260" height="36" title ="Check out with PayPal">\' );
</script>
;'
}

if you already are using the scripts hook, just add this to the existing code.

<script> 
 $( "#cart-buttons form input" ).replaceWith( \'<input type="image" name="submit" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/cc-badges-ppmcvdam.png" alt="Pay with PayPal, PayPal Credit or any major credit card" border="0" align="top" width="260" height="36" title ="Check out with PayPal">\' );
 </script>

In place of the PayPal button address that’s currently there (everything starting with https:// and ending with .png), paste in the code for the one you’re using. (The backslashes that you see are “escape” characters so that the code will use them literally rather than interpret them as jQuery code).

To better control the appearance, I’ve added width and height attributes. The height attribute should stay at 36 but you may need to experiment with the width attribute.

Thanks to Daniel Leu for his coding suggestion in the comments below. I’ve edited this post to incorporate it. Be sure to visit the site linked in his name for more TTG fun.

3 thoughts on “Change the PayPal button in your TTG Cart”

  1. Hey Rod,

    Neat trick. It might work as well using ….replaceWith( \’…\’); In this case, you will not need to escape all the double quotes.

    Cheers, Daniel

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About this site

This site is: a repository of time-savers and best practices from a user's perspective, picked up from several years of using TTG plugins.
This site is not: a support site.
Read more here.

Subscribe to new posts

Tip Jar

If this site has saved you some time, kept your hair attached, or otherwise prevented you from tossing the mouse through the monitor, feel free to donate.

Categories


Highly recommended. This is my go-to Lightroom book. Click on the book image. (affiliate link)

Affiliate link!

Current TTG versions

Backlight  4 & 5

See the Backlight Modules page on your site for latest Backlight and module versions and changelogs.

You’ll also find the latest version number and download link for the Lightroom Publisher plugin.
(BL 3 and later)

 

Backlight 1 Versions

Backlight 1.2.4
Pages module 1.2.4
Cart Add-on 4.1.7
Client Response Add-on 7.1.3
Theater Add-on 1.2.6
Galleria Add-on 1.0.0
WordPress Add-on 1.2.6
Publisher 3.2.3

Backlight 1 has seen its end of life. See this post.

CE4 Versions

note: CE4 is no longer being developed or sold. See this post.

TTG-BE: 2.0.5a
Autoindex: 7.0.8
Cart: 3.1.4a
CRG: 6.1.3a
Gallery: 6.1.10
Pages: 7.0.15
Publisher: 2.3.3
Stage: 6.1.6
Theme for WordPress: 3.1.2