- This topic has 8 replies, 2 voices, and was last updated 4 years, 11 months ago by Tom.
-
AuthorPosts
-
May 3, 2019 at 8:20 am #888036James
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 Premium2. 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.
May 3, 2019 at 8:32 am #888060TomLead DeveloperLead DeveloperHi 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 π
May 3, 2019 at 1:18 pm #888300JamesYou 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. π
May 3, 2019 at 1:37 pm #888310TomLead DeveloperLead DeveloperCode 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' ); } } } );
May 3, 2019 at 5:13 pm #888407JamesDefinitely 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?
May 3, 2019 at 5:50 pm #888421JamesAfter 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.
May 4, 2019 at 7:36 am #888931TomLead DeveloperLead DeveloperAh yea – sorry. I assumed WooCommerce.
Your PHP looks good to me π
May 4, 2019 at 8:06 am #888967JamesNo worries! You definitely helped point me in the right direction. Was just a matter of learning a little about wp conditional tags. Thanks again!
May 4, 2019 at 8:08 am #888970TomLead DeveloperLead DeveloperNo problem π
-
AuthorPosts
- You must be logged in to reply to this topic.