I need to add two numbers
-
I am using WP e-commerce Version 3.8.7.6.2 with WordPress 3.3.1.
My website is https://www.greenhillsoaps.I am working on my checkout page.
At the top of the page is the content of the shopping cart. I have found a way to sum the totals in the cart. In wp-e-commerce/wpsc-includes/cart.class.php I found a range of functions that control how the shopping cart works. One of these functions is as follows:
function wpsc_cart_total_widget( $shipping = true, $tax = true, $coupons = true ) { global $wpsc_cart; $total = $wpsc_cart->calculate_subtotal(); if ( $shipping ) { $total += $wpsc_cart->calculate_total_shipping(); } if ( $tax && wpsc_tax_isincluded() == false ) { $total += $wpsc_cart->calculate_total_tax(); } if ( $coupons ) { $total -= $wpsc_cart->coupons_amount; } if ( get_option( 'add_plustax' ) == 1 ) { return wpsc_currency_display( $wpsc_cart->calculate_subtotal() ); } else { return wpsc_currency_display( $total ); } }
By including this function with all the terms set to false, I was able to get a total of the purchases in the cart. I then found the function for the tax calculation. That function is:
function wpsc_cart_tax($forDisplay = true) { global $wpsc_cart; if($forDisplay){ if(wpsc_tax_isincluded() == false){ return wpsc_currency_display($wpsc_cart->calculate_total_tax()); }else{ return '(' . wpsc_currency_display($wpsc_cart->calculate_total_tax()) . ')'; } }else{ return $wpsc_cart->calculate_total_tax(); } }
I then took the first function and added it to a line with the terms set to false, false, true and the result was the sum of the first two. So the beginning of the checkout looks somewhat like this:
Please review your order
Product Quantity Price Total
No Image Arabian Magic $8.50 $8.50
Citrus Sunshine Citrus Sunshine $8.00 $8.00
Honey Bee Bar Honey Bee Bar $8.00 $8.00
Moulin Rouge Moulin Rouge $7.75 $7.75
Order Total $32.25
Tax $2.38
Order Total Before Shipping $34.63Order Total is computed with the widget set as follows:
<?php echo wpsc_cart_total_widget(false,false,false);?>
Order Total Before Shipping is computed with the widget set this way:
<?php echo wpsc_cart_total_widget(false,false,true); ?>
This results is the correct total for the cart + taxes, before shipping costs.
The customer then calculates the shipping and chooses the best rate.
In this instance the shipping costs are $5.30.
So the total purchase, including shipping should be $39.93.They enter their bill to and ship to information.
And at the bottom of the page just before purchase is the following:Review and purchase
Order Total: $34.63
Total Shipping: $5.30
Purchase Total $34.63What I did was use the cart widget and changed the settings. So the code for order total is:
<?php echo wpsc_cart_total_widget(false,false,true); ?>
Then the code for the shipping is from the shipping calculation and it is as follows:
<?php if(wpsc_uses_shipping()) : ?> <tr class="total_price total_shipping"> <td class='wpsc_totals'> <?php _e('Total Shipping', 'wpsc'); ?>: </td> <td class='wpsc_totals'> <span id="checkout_shipping" class="pricedisplay checkout-shipping"><?php setlocale(LC_MONETARY, "en_US"); echo "$".number_format(wpsc_shipping_quote_value(true), 2, '.', ','); ?></span> </td> </tr> <?php endif; ?>
I had to change the last piece of this so it would compute and display properly. So the section begining with <?php setlocale(LC_MONETARY….. is my change. However, it does compute the shipping correctly.
Then to sum these two amounts, my final piece of code is as follows:
<tr class="order_total_price"> <td class='text-order-total'> <span id="purchase_total" class="pricedisplay order-total"><?php echo('Purchase Total'); ?></span> </td> <td id=currency-purchaser-total colspan="3"> <span id='purchase_total' class="pricedisplay checkout-total"><?php echo wpsc_cart_total_widget(); ?></span> </td> <tr/>
note that the cart total widget has no values in it. If I put what I would have expected (true, true, true) I get the $39.93. But this changes the order total from $34.63 to $39.93, both here at the bottom of the check out and at the top by the cart.
Clearly I am doing something wrong. I really would like some help with this. I can post the whole PHP file for the cart if that would help. I think there should be a simple what to add the two values produced by the PHP function and display them as the purchase total. But how to do that has successfully evaded me.
Thanks!
- The topic ‘I need to add two numbers’ is closed to new replies.