Last active
August 22, 2017 23:55
-
-
Save asalkey/d4b41f5726889aa41edd to your computer and use it in GitHub Desktop.
Woocoomerce: pull total with ajax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add an extra key + value | |
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment'); | |
function woocommerce_header_add_to_cart_fragment( $fragments ) { | |
global $woocommerce; | |
ob_start(); | |
?> | |
<div class="total"> <?php echo $woocommerce->cart->get_cart_total(); ?> </div> | |
<?php | |
$fragments['total'] = ob_get_clean(); | |
return $fragments; | |
} | |
// Create ajax callback function function | |
your_php_ajax_function(){ | |
$ajax = new WC_AJAX(); | |
$ajax->get_refreshed_fragments( ); | |
} | |
// Get json data | |
jQuery.ajax({ | |
type:'POST', | |
url: '/wp-admin/admin-ajax.php', | |
data: use_points_processing, | |
success:function(data){ | |
console.log(data.fragments.total); } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment