• Resolved Richard Webster

    (@rwebster85)


    Hey guys, firstly fantastic job with this plugin. I’m in the process of switching over from WooCommerce for a pretty big project I’m working on, but missing something I really like…

    You guys have a cart quantity fragment that updates with ajax, but I can’t find a £ total value that does the same.

    I think I read a post by Pippin from a while ago that said this feature was coming in 1.8.3 but I don’t see it.

    Is this something I’m going to have to code up myself? In an ideal world there would be a version of the following for cart value:

    <a href="<?php echo edd_get_checkout_uri(); ?>">
    	Cart (<span class="header-cart edd-cart-quantity"><?php echo edd_get_cart_quantity(); ?></span>)
    </a>

    Cheers all, keep up the great work.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Do you have the currency set to £ in settings?

    Thread Starter Richard Webster

    (@rwebster85)

    I do mate yes. I didn’t mean £ as GBP though, I meant just the monetary total. Bit of lazy shorthand.

    Ah, I see now. You are looking for edd_get_cart_total().

    Here is how we do this in the Vendd theme:
    <?php printf( __( 'Cart total: %s', 'vendd' ), '<span class="header-cart-total">' . edd_currency_filter( edd_format_amount( edd_get_cart_total() ) ) . '</span>' ); ?>

    https://github.com/easydigitaldownloads/vendd/blob/master/header.php#L85
    https://github.com/easydigitaldownloads/vendd/blob/master/inc/js/vendd-scripts.js#L26

    Thread Starter Richard Webster

    (@rwebster85)

    Thanks mate, that doesn’t update using Ajax though, like the cart quantity does. I’m looking for the cart value total equivalent of the cart quantity ajax function in my OP ??

    You will just need a specific class name on it. When adding an item to the cart, the following fires:

    $('.edd-cart-meta.edd_subtotal span').html( response.subtotal );

    So you will just need an HTML element with a class of class="edd-cart-meta edd_subtotal" and span tag inside it.

    Thread Starter Richard Webster

    (@rwebster85)

    Nah it’s not playing nice. I can see this needing a custom solution. I can only get it to output what the little cart widget displays, which is text plus quantity plus total:

    Test Download – 1 @ £5.00 – remove

    I’ll have to put this aside for now, time is precious, and fancy things like this aren’t urgent. I was hoping it would be simple like in WooCommerce, just a quick action/function in php ??

    Thread Starter Richard Webster

    (@rwebster85)

    I see the Vendd theme has this, top right of the header. I’ll take a peek under the hood.

    Thread Starter Richard Webster

    (@rwebster85)

    Ok, resolved.

    I’ve seen a number of posts on this, so thought I’d post this simple solution, c/o the guys behind Vendd.

    Code to display the cart text, put it anywhere, like your header or nav or something:

    <a href="<?php echo edd_get_checkout_uri(); ?>" class="header-cart">
    	<?php printf( __( 'Cart total: %s', 'vendd' ), '<span class="header-cart-total">' . edd_currency_filter( edd_format_amount( edd_get_cart_total() ) ) . '</span>' ); ?>
    </a>

    Now place this into your JS file.

    $( document ).ready( function() {
    	body = $( document.body );
    
    	body = $( document.body );
    	var header_cart_total = $('.header-cart-total');
    	body.on('edd_cart_item_added',function(event, response){
    		header_cart_total.html(response.subtotal);
    	});
    	body.on('edd_cart_item_removed',function(event, response){
    		header_cart_total.html (response.subtotal);
    	});
    });

    Customise as you see fit ??

    Thread Starter Richard Webster

    (@rwebster85)

    Can’t edit now… remove that second body = line ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Ajax update cart total’ is closed to new replies.