Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_single_product_summary', 'woocommerce_total_product_price', 31 );
- function woocommerce_total_product_price() {
- global $woocommerce, $product;
- // let's setup our divs
- echo sprintf('<div id="product_total_price" style="margin-bottom:20px;">%s %s</div>',__('Product Total:','woocommerce'),'<span class="price">'.$product->get_price().'</span>');
- ?>
- <script>
- jQuery(function($){
- var price = <?php echo $product->get_price(); ?>,
- currency = '<?php echo get_woocommerce_currency_symbol(); ?>';
- $('[name=quantity]').change(function(){
- if (!(this.value < 1)) {
- var product_total = parseFloat(price * this.value);
- $('#product_total_price .price').html( currency + product_total.toFixed(2));
- }
- });
- });
- </script>
- <?php
- }
- function add_gift_wrap_field() {
- echo '<table class="variations" cellspacing="0">
- <tbody>
- <tr>
- <td class="label"><label>More price: </label></td>
- <td class="value">
- <input type="number" name="more_price"/>
- </td>
- </tr>
- </tbody>
- </table>';
- }
- add_action( 'woocommerce_before_add_to_cart_button', 'add_gift_wrap_field' );
- function save_gift_wrap_fee( $cart_item_data, $product_id ) {
- if( isset( $_POST['more_price'] ) && $_POST['more_price'] != '' ) {
- $cart_item_data[ "more_price_fee" ] = $_POST['more_price'];
- }
- return $cart_item_data;
- }
- add_filter( 'woocommerce_add_cart_item_data', 'save_gift_wrap_fee', 99, 2 );
- function calculate_gift_wrap_fee( $cart_object ) {
- if( !WC()->session->__isset( "reload_checkout" )) {
- /* Gift wrap price */
- // $additionalPrice = 100;
- foreach ( $cart_object->cart_contents as $key => $value ) {
- if( isset( $value["more_price_fee"] ) ) {
- /* Woocommerce 3.0 + */
- $orgPrice = floatval( $value['data']->get_price() );
- $more = floatval($value["more_price_fee"]);
- $value['data']->set_price( $orgPrice + $more );
- }
- }
- }
- }
- add_action( 'woocommerce_before_calculate_totals', 'calculate_gift_wrap_fee', 99 );
- function render_meta_on_cart_and_checkout( $cart_data, $cart_item ) {
- $meta_items = array();
- /* Woo 2.4.2 updates */
- if( !empty( $cart_data ) ) {
- $meta_items = $cart_data;
- }
- if( isset( $cart_item["more_price_fee"] ) ) {
- $meta_items[] = array( "name" => "More", "value" => $cart_item['more_price_fee'] );
- }
- return $meta_items;
- }
- add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 99, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement