10

I am new to WordPress/WooCommerce. I am trying to make Quick View, Add To Cart function from pop up fancybox in Variable Products.

I found and wrote below code; it's working when a customer is logged in but for guest user its showing message that product is added to cart but in the actual cart it's not adding.

I am using

WordPress version: 4.3.1

WooCommerce version: 2.4.12 

Plugins: woocommerce-ajax-add-to-cart-for-variable-products

<?php include 'wp-load.php'; ?>

    <script src="<?php echo get_site_url() ?>/jquery.min.js"></script>
    <script type='text/javascript' src='<?php echo get_site_url() ?>/wp-content/plugins/woocommerce/assets/js/frontend/single-product.min.js'></script>
    <script type='text/javascript' src='<?php echo get_site_url() ?>/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart.min.js'></script>
    <script type='text/javascript' src='<?php echo get_site_url() ?>/wp-content/plugins/woocommerce-ajax-add-to-cart-for-variable-products/js/add-to-cart-variation.min.js'></script>
    <script type='text/javascript' src='<?php echo get_site_url() ?>/wp-content/plugins/woocommerce/assets/js/frontend/add-to-cart-variation.min.js'></script>

<?php global $product, $woocommerce, $yith_wcwl_init; ?>
<?php wc_print_notices(); ?>
<?php 
    woocommerce_variable_add_to_cart();
    echo do_action( 'woocommerce_add_to_cart_form' ); 
?>

Thanks In Advance.

Krupal Panchal
  • 1,553
  • 2
  • 13
  • 26
user2134
  • 177
  • 2
  • 15
  • 3
    _“This plugin hasn’t been tested with the latest 3 major releases of WordPress.”_, _“Last updated: 2 years ago”_ ... i think you should perhaps start with something more up to date. – CBroe Mar 16 '18 at 08:41
  • As CBroe stated the plugin is not being updated anymore. I would give it a try with these links: https://diviengine.com/woocommerce-add-cart-ajax-single-variable-products-improve-ux/ & https://stackoverflow.com/questions/27270880/add-a-variation-to-cart-using-ajax-woocommerce-api/27278035#27278035 – Omar Tanti Mar 18 '18 at 05:58
  • Ajax call issues with logged in/out users usually have to do with `wp_ajax` and `wp_ajax_nopriv` actions. If you want and ajax call to be available for both logged in and logged out users both `wp_ajax` and `wp_ajax_nopriv` have to be added. You can find more information here: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_nopriv_(action) – Omar Tanti Mar 18 '18 at 06:11
  • I'm wondering why you need to build this. WooCommerce can already set the add to cart button to work with AJAX. It's a tickbox setting in WooCommerce options. – James Jones Mar 18 '18 at 08:21
  • https://stackoverflow.com/questions/27168479/woocommerce-cant-add-to-cart-as-a-guest-using-quick-order-one-page-shop – Chintan Hingrajiya Jun 27 '18 at 06:35
  • be sure that jquery is enqueued for non logged in users...because of admin bar its automatcally for logged in users – theode Aug 30 '18 at 20:57

1 Answers1

1

Kindly goto Woocommerce - Settings Navigate to "Account and Privacy" in Guest Checkout tick "Allow customers to place orders without an account" enter image description here

rushabhpathak
  • 173
  • 1
  • 16