Search code examples
phpwordpresswoocommercecartfloating

Reload PHP If/Else Statement in cart footer without reloading whole page? ( XT Floating Cart)


The code is as below: I am getting a total number of items from woocommerce cart and I am showing a specific footer on a specific quantity. ** Everything is working fine but the problem is i want it to update the footer also with floating cart body without reloading the whole page.** Every time I have to reload Want to Achieve:

  • Update Footer Div/Page According to quantity means a user need to have a total of 10 items in the cart to checkout
  • But the whole page should not reload it just should be the floating cart. By the way I am using XT floating cart Will be really Appreciated
<?
    $min = 10;
    if(WC()->cart->cart_contents_count < $min)
    {
        xt_woo_floating_cart()->get_template( 'parts/cart/custom_footer' );
    }
    else
    {
        xt_woo_floating_cart()->get_template( 'parts/cart/footer' );
    }       
?>

Solution

  • Shams what you're attempting to achieve is unfortunately not what PHP was built for.

    When you submit a request to PHP it runs through the code, interprets it and renders the page server side, before sending the HTML, CSS and JS to the user. Therefore, you cannot reload just part of page without reloading the whole page.

    One way you can achieve your desired functionality is to create a controller. Creating a controller means you create a PHP function that sits at at specific web URL. You can parse an object to this URL and the URL can parse you an object back.

    Once you have created the controller you need to create the caller. Usually these front end calls are made using Javascript. You can wait for a user to complete an action than then use AJAX to send a request to your controller. Your controller can return some data and you can use javascript to manipulate the DOM to alter the page without reloading the whole page.

    Please note that this is just one way of achieving your desired functionality and requires some knowledge of programming. However, if you're determined and happy to learn you can use the information above research how to program an approach like this.