Tagged: 

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #958085

    I am trying to get total price calculation in woocommerce single product page with AJAX. Means, whenever I increase or decrease the quantity, the price should also increase or decrease at the same time without page upload. I referred the following link for this.

    https://gist.github.com/alexanderdejong/60508c02eb5ff32b8e16a88936836832

    Now why I am asking this thing in enfold support? Because the solution in the above link is working correctly in other themes, like the default themes, X-theme. But not in enfold. I am using ‘code snippets plugin’ to insert the codes. I also tried by inserting in functions.php file directly, but not working. I am using Enfold for almost a year, I love it, but got a bit disappointed with this issue. I really don’t want to switch theme just because of this issue. Please have a look at this issue. I am providing the credentials of a new setup, in private as told. Thanks.

    #959564

    Hey websevent_1321,

    Thank you for using Enfold.

    The filter may require a few adjustments. Please try this instead.

    add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 25 );
    function woocommerce_total_product_price() {
        global $woocommerce, $product;
        // let's setup our divs
        echo sprintf('<div id="product_total_price" style="font-size: 16px; font-weight: 200;">%s %s</div>',__('Total Price (incl Tax):','woocommerce'),'<span class="price">'. get_woocommerce_currency_symbol() .' ' .$product->get_price().'</span>');
        ?>
            <script>
                jQuery(function($){
                    var price = <?php echo $product->get_price(); ?>,
                        currency = '<?php echo get_woocommerce_currency_symbol(); ?>',
    					qtycont =  $('.quantity'),
    					qty =  qtycont.find('[name=quantity]');
    
    					qty.attr('data-qty', 1);
    
    				qtycont.on('click', '.plus, .minus', function(){
    					var qtythis = $(this).find('[name=quantity]');
    					var qtyNum = $(qtythis.selector).attr('data-qty');
    					var totalQty = parseInt(qtyNum);
    					
    					if($(this).is('.plus') && qtyNum < $(qtythis.selector).attr('max')) {
    						totalQty = parseInt(qtyNum) + 1;
    						$(qtythis.selector).attr('data-qty', totalQty);
    						
    					} else if($(this).is('.minus') && qtyNum > $(qtythis.selector).attr('min')) {
    						totalQty = parseInt(qtyNum) - 1;
    						$(qtythis.selector).attr('data-qty', totalQty);
    					}
    
                        if (!totalQty < 1) {
                            var product_total = parseFloat(price * totalQty);
                            $('#product_total_price .price').html( currency + product_total);			
                        }	
                    });
                });
            </script>
        <?php
    }
    

    Best regards,
    Ismael

    #959588

    Thank you Ismael for your help, but unfortunately, it’s not working. I have shared the test logins, please check.

    #960163

    Hey!

    Thanks for the update.

    It works now. We adjusted the script a bit. You should now see the total price above the add to cart button.

    // http://test.sdlcontentservices.com/product/a-product/

    // https://pastebin.com/FnKC9duc

    Best regards,
    Ismael

    #961969

    Hi Ismael, yeah it works nicely.
    One more thing, if its possible. I am trying to implement an assignment help service. Suppose the product price is $10, then my assignment(product) price will be like $10 per page (250 words).
    Now in the above solution which you provide solves half of the work. i.e. when a buyer increases the product quantity, it means the buyer is increasing the number of pages. So, for 1 page it is $10, for 2 pages it is $20 and so on. It updates the prices as the number of pages(quantity) increases.
    What I want is, it could also update the number of words simultaneously along with the price. Like:
    For 1 page it should show – “$10 per page (250 words)”
    For 2 pages it should show – “$20 per page (500 words)”
    For 3 pages it should show – “$30 per page (750 words)”
    For 4 pages it should show – “$40 per page (1000 words)”
    For 5 pages it should show – “$50 per page (1250 words)”
    and so on.
    Is it possible here? Please let me know. And in case you want to play around with the code, the admin details are the same, please use that. Than you so much.

    #962950

    Hi,

    Yes, that is possible. Modify this line.

    $('#product_total_price .price').html( currency + product_total);
    

    Replace it with…

    $('#product_total_price .price').html( currency + product_total + ' per page (' + (totalQty * 250) + ' words)');
    

    Best regards,
    Ismael

    #963524

    Hi Ismael, thank you for the solution. There is just an issue. Not exactly issue. Just this “no. of words” is not getting forwarded to cart page, checkout page, and customer invoice. Is it possible to render “number of words” further along with other data? Thank you.

    #965125

    Hi,

    We adjusted the code a bit. Please remove browser cache prior to checking the page.

    Best regards,
    Ismael

    #965154

    Hi Ismael, I am thankful for your effort, but it’s not working as expected. Instead, it disrupted the 250+ word counter. Please have a look again.

    #966353

    Hi Ismael, I am thankful for your effort, but it’s not working as expected. Instead, it disrupted the 250+ word counter. Please have a look again.

    #967509

    Hi,

    I did assigned task to Ismael, so he can review yes. :)

    Best regards,
    Basilis

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.