0

I'm doing a Progress Bar Shopping Experience (in my WooCommerce site). First the user select the plan (demo, home, business, premium), then select the products he wants, and finally I've to show them the cart table. I use the following code to send the items using AJAX (In the same template):

<?php
    if(isset($_POST['action'])) 
    {
      global $woocommerce;
      $woocommerce->cart->empty_cart(true);                 
      $woocommerce->cart->add_to_cart( 2932, 30 );

      echo do_shortcode('[woocommerce_cart]');
      die();
    }
?>
<?php get_header(); ?>  
<script type="text/javascript">
  var serializedOrderForm ='action=update_cart_order';                       

          jQuery.ajax({
              type: 'POST',
              data: serializedOrderForm
          })
          .done(function(data){
              console.log(data);
              jQuery("#p1content3").html(data);
          })
          .fail(function( jqXHR, textStatus, errorThrown ) {
              console.log(jqXHR);
              console.log(textStatus);
              console.log(errorThrown);
              jQuery("#p1content3").html("<div class='alert'>Ha Ocurrido un Error al Procesar la Orden</div>");
          });
</script>

<div id="p1content3"></div>
<?php echo do_shortcode('[woocommerce_cart]');?>

<?php get_footer(); ?>
<?php get_sidebar(); ?>

My problem is that the table (the first one) that return the AJAX is WITHOUT the price discounts of the plugin "woocommerce dynamic pricing discounts".

But if inside any template i use:

  <? echo do_shortcode('[woocommerce_cart]'); ?>

Its return the table (second table) WITH the price discounts...

You can see the example here: http://cl.galyleo.net/prueba-carro/ of the code with the 2 cases.

Any ideas?

5
  • I admit I do not have any WooCommerce experience, but that said, why are you doing a die() at the end of your function? I'd imagine that'd kill everything that runs AFTER your function is called & completed...? Just a thought.
    – Pat
    Aug 19, 2014 at 16:13
  • That is because is an ajax call Aug 19, 2014 at 17:17
  • I change my example to a simplier one, as you can see the die() is for the ajax call, checkout the example page for better understanding Aug 19, 2014 at 17:32
  • 1
    You need to put the die() inside a function that is called by the ajax request. Search this site for an ajax example and then go from there. Here's one of my answers on it: wordpress.stackexchange.com/questions/96795/… Aug 19, 2014 at 17:43
  • Mmm I doubt that the die() has the fault here... As you could see in my example page, my code works... and i tried using the WP AJAX API but the same happen... so as you can see my problem is with the output of the do_shortcode (check the page) because directly in template i get the result i want (with de plugin) but if i do it with an ajax call the plugin dont work (any of the filter and actions of the plugins arent executed) Aug 19, 2014 at 18:15

1 Answer 1

0

All AJAX calls in WordPress run through admin. So if you wrap something inside

if ( ! is_admin() )
{
    // stuff
}

then the AJAX call would not be able to know about this part. In other words, it does not get executed. I don't know what this plugin specifically does, but if only one part does not get executed, there's a high chance that this is the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.