[Resolved] Using theme with "WP Simple PayPal Shopping Cart" – jQuery Checkout Error

Home Forums Support [Resolved] Using theme with "WP Simple PayPal Shopping Cart" – jQuery Checkout Error

Home Forums Support Using theme with "WP Simple PayPal Shopping Cart" – jQuery Checkout Error

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #888036
    James

    Hello,
    I have a small ecommerce store that I just recently switched to GP Premium. Unfortunately there seems to be an issue with the PayPal Smart Checkout process when using WP Simple PayPal Shopping cart plugin. I’ve had two different customers email over the past couple days saying they’re not able to checkout. Today I did some testing via PayPal sandbox and discovered something between the WP Simple PayPal Shopping Cart and GP Premium aren’t playing together nicely.

    Specifically during the last part of checkout via PayPal customers see the following error message:
    Error occurred during PayPal Smart Checkout process. ReferenceError: jQuery is not defined.

    I’m using autoptimize and caching solutions, so naturally I suspected those first. The issue persisted after deactivating them.

    Here’s what I know:
    1. The issue started after switching to GP Premium

    2. Test transactions process normally with two other themes with all the same plugins activated. When I switch back to GP, checkout fails again. I’ve used the site’s previous theme and Twenty Seventeen without issue.

    3. I’m sure I could resolve this by switching to a different ecommerce plugin, like woocommerce, but I’d like to avoid this work if possible.

    4. This site is on PHP 7.2, WordPress 5.1.1, GP 2.2.2, GP Premium 1.8.2

    Any help on where to start is greatly appreciated. I definitely don’t want to switch themes and moving the site over to woocommerce is a very last resort for a variety of reasons.

    #888060
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Is jQuery added to your site? GeneratePress doesn’t add it by default, so you might need to add it:

    add_action( 'wp_enqueue_scripts', function() {
        wp_enqueue_script( 'jquery' );
    } );

    If it is added, you might need to exclude it inside the Autoptimize settings. Check out our recommended settings here: https://generatepress.com/fastest-wordpress-theme/

    GP Premium itself shouldn’t cause conflicts like this. If the above doesn’t work, it’s possible you’ve added something in Elements (a Hook maybe) that’s causing the error.

    Let me know πŸ™‚

    #888300
    James

    You were correct. I assumed the site was already loading jQuery since it’s included with WordPress and since I saw it in the source code when I first began troubleshooting. Unfortunately it looks like this plugin does something weird and doesn’t properly work if the theme doesn’t include it.

    At any rate, I added your php via the code snippets plugin and set it to run on the frontend only. Is this OK performance-wise or is there a better way?(Creating a child theme functions.php just for this seemed like overkill.)

    I tried adding the code via a wp_header or wp_footer hook in Hooks Elements but I couldn’t get it to work. Ideally I was hoping to just load/enqueue jquery on the cart and checkout pages for the ecommerce plugin. It didn’t seem to work for me with setting location display rules for those pages. Then again, I clearly don’t know what I’m doing. πŸ˜‰

    #888310
    Tom
    Lead Developer
    Lead Developer

    Code Snippets is definitely the way to go if you don’t have a child theme.

    You could try this:

    add_action( 'wp_enqueue_scripts', function() {
        if ( function_exists( 'is_cart' ) && function_exists( 'is_checkout' ) ) {
            if ( is_cart() || is_checkout() ) {
                wp_enqueue_script( 'jquery' );
            }
        }
    } );
    #888407
    James

    Definitely pretty new to this, but I’m guessing the is_cart and is_checkout are WooCommerce Conditional functions? That code didn’t work because I’m using the WordPress Simple PayPal Shopping Cart.

    Is there any way to have GeneratePress/GP Premium enqueue JQuery only on the checkout and cart page using page id or something similar?

    #888421
    James

    After a bit of playing around this seems to work. Not sure whether this is the correct way of doing things but I added this code snippet:

    add_action( 'wp_enqueue_scripts', function() {
       if (is_page( array(84, 37))) {
                wp_enqueue_script( 'jquery' );
    	    }
    });

    Seems to be working at first glance.

    #888931
    Tom
    Lead Developer
    Lead Developer

    Ah yea – sorry. I assumed WooCommerce.

    Your PHP looks good to me πŸ™‚

    #888967
    James

    No worries! You definitely helped point me in the right direction. Was just a matter of learning a little about wp conditional tags. Thanks again!

    #888970
    Tom
    Lead Developer
    Lead Developer

    No problem πŸ™‚

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.