Site logo

[Resolved] total Price on product page

Home Forums Support [Resolved] total Price on product page

Home Forums Support total Price on product page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2553968
    Jusung

    Hello. I am trying to customize the product page now
    and for the total price, I added this code

    add_action( 'woocommerce_single_product_summary', 'action_woocommerce_single_product_summary', 31, 0 );
    
    function action_woocommerce_single_product_summary() {
        global $product;
        
        $price = $product->get_price();
        $currency_symbol = get_woocommerce_currency_symbol();
        $min_qnty = $product->get_min_purchase_quantity();
        $initial_price = floatval($price) * intval ($min_qnty);
        
        // leave the span class 'prezzo' as it is or it won't render the price
        echo sprintf('<div id="product_total_price">%s %s</div>', __('Total:','woocommerce'), '<span class="prezzo">' . $currency_symbol . $initial_price . '</span>' );
        ?>
        <script>
        jQuery(function($) {
            // vars
            var price = <?php echo $price; ?>, 
                currency = '<?php echo $currency_symbol; ?>',
                quantity =  $( '[name=quantity]' ).val();
                
            var product_total = parseFloat( price * quantity );
            $( '#product_total_price .prezzo' ).html( currency + product_total.toFixed( 2 ) );
                
            // On change
            $( '[name=quantity]' ).change( function() {
                if ( ! ( this.value < 1 ) ) {
                    product_total = parseFloat( price * this.value );
    
                    $( '#product_total_price .prezzo' ).html( currency + product_total.toFixed( 2 ) );
                }
            });
        });
        </script>
        <?php
    }

    This code works well and the total price is below “add to cart” button since I gave 31.
    Is there a way to put the total price on the “add to cart” button..?
    I tried to use (hook: after quantity), but it breaks the page.

    #2553975
    Jusung

    maybe I can make a shortcode for this function..?

    #2553992
    Jusung

    It is resolved!

    I just used different filter, which is this
    woocommerce_after_add_to_cart_button

    thank you!

    #2554056
    David
    Staff
    Customer Support

    Glad to hear you found the answer!

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