I noticed that the woocommerce add to cart button was not working on some mobile devices and browsers on a client website. So let’s start debugging…
I tested this on iPhone 5c with Safari and the product did not get added to the cart. Using the Safari developer tools I managed to detect an error in some JavaScript that was not showing up in any other browsers on the desktop running mobile user agents.
Error: Syntax error, unrecognized expression: form.cart input[name="variation_id]
The error seems to be generating from this file:
/wp-content/plugins/synmedia-woocommerce-rewards/assets/js/jquery.swr.product.js
There is an error in this file from the plug-in: Syn Media WooCommerce Rewards, version 2.3.6
On line 9 both quotes are missing arround the variable: variation_id
function swr_variations_options_changed(){
if($('form input[name=variation_id]').val() != ''){
swr_options_changed();
} }
On line 18 and 19
variation_id variable is missing the closing quote (“) on both lines.
function swr_options_changed(){
var product_id = 0;
var variation_id = 0;
var qtys = '';
if( $( 'form.cart input[name="variation_id]' ).length > 0 ){ v
ariation_id = $('form.cart input[name="variation_id]').val();
.....
Changing the above code with the correct quotes fixed the issue on the website. Now also mobile devices can add products to the shopping cart.