Plugin Directory

Changeset 1827446


Ignore:
Timestamp:
02/23/2018 04:55:50 AM (8 years ago)
Author:
zheng4uga
Message:

update code to handle latest woocommerce

Location:
additional-charge/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • additional-charge/trunk/README.md

    r1655616 r1827446  
    1 ===Woocommerce Additional Charge ===
     1=== Additional Charge ===
    22
    33Contributors: Yong Qui Zheng
    4 Tags: woocommerce, extra charge, donation, surcharge, delivery, tips, shipping
     4Tags: woocommerce, extra charge, additional charge, surcharge, delivery tip, tips, shipping,donation
    55Version:1.0.0
    66Requires at least: 3.2.1
    7 Tested up to: 4.7.4
     7Tested up to: 4.2.2
    88Stable tag: 1.0.0
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     11
     12## Motivation
    1113
    1214Provide a way for customer to add additional charge to WooCommerce checkout. It is useful for site that would like to do delivery service. Tipping service or anything that will allow customer to add a percent of their checkout price.
     
    2729* Provide an additional box under the note section that will allow customer to add their tips, donations, etc base on total price
    2830
     31= 1.0.1 =
    2932
     33* Fixed issue where additional charge does not persist after checkout phrase on the woocommerce 3.8.x
     34
     35
  • additional-charge/trunk/class.additionalcharge.php

    r1655604 r1827446  
    4848                add_action('wp_ajax_add_charge',array('AdditionalCharge','add_charge'),10);
    4949                add_action('woocommerce_cart_calculate_fees', array('AdditionalCharge','add_charge_cost_from_session'),10);
    50 
     50                add_action('woocommerce_thankyou',array('AdditionalCharge','unset_charge_session'),10);
    5151    }
     52        public static function unset_charge_session(){
     53            // we need to unset the charge value in the session after order has been placed
     54            unset($_SESSION['charge_value']);// try to unset the session before checkout cart begin
     55        }
    5256       
    5357        public static function add_charge(){           
     
    6569        }
    6670        public static function add_charge_cost_from_session() {
    67             global $woocommerce;
    68             $cart=$woocommerce->cart;
     71            $cart= wc()->cart;
    6972            $charge=$_SESSION['charge_value'];
    70             if($charge!=null){
     73            if(!empty($charge)){
    7174                $charge_label= empty(get_option(self::$fee_label_var))?self::$default_fee_label:get_option(self::$fee_label_var);
    7275                $cart->add_fee($charge_label,$charge);
    73                 unset($_SESSION['charge_value']);
    7476            }
    7577        }
Note: See TracChangeset for help on using the changeset viewer.