Get cart total after page is laoded
-
I need to get the amount of cart total after the page is already loaded.
For example, I use the below code to display the total on cart page (I’m replacing the default woocommerce cart page if you are curious why I am doing this, so I’m basically making the cart page from scratch):
echo WC () -> cart -> get_total ()
But the amount won’t be updated after the coupon is added or removed, so I planned to refresh/update the amount with Ajax if the button is click.
Below is the JS code:
const getData = fetch('https://test.local/wp-content/themes/test/process.php') .then(response => response.text()) .then(response => console.log(response)); test.addEventListener('click', function() { text.innerText = getData; });
For
process.php
, it looks like this:<?php echo WC () -> cart -> get_total () ?>
Apparent it won’t wotk because the page is already loaded, I cannot access
WC ()
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Get cart total after page is laoded’ is closed to new replies.