WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce Add Charges To Payment Gateway
woocommerce 2.1.1 (16 posts)

  1. piskello
    Member
    Posted 6 months ago #

    Hello,
    I noticed that your (great) plugin doesn't work with the latest versione of woocommerce :( is there a quick fix?
    thank you for you r work
    matteo

    https://wordpress.org/plugins/woocommerce-add-extra-charges-option-to-payment-gateways/

  2. monofase
    Member
    Posted 6 months ago #

    I also tried with woocommerce 2.12 and WP 3.8.1 and it's not working!
    Please fix it, is a very useful plugin

  3. mindkil
    Member
    Posted 6 months ago #

    Please update it to Woocommerce 2.1.2
    Thanks!

  4. Dalibr
    Member
    Posted 5 months ago #

    Please update!

  5. aaarghhh
    Member
    Posted 5 months ago #

    In function "woocommerce-add-extra-charges-option-to-payment-gateways.php" i Patched the function like this:

    function add_form_fields(){
            global $woocommerce;
             // Get current tab/section
            $current_tab        = ( empty( $_GET['tab'] ) ) ? '' : sanitize_text_field( urldecode( $_GET['tab'] ) );
            $current_section    = ( empty( $_REQUEST['section'] ) ) ? '' : sanitize_text_field( urldecode( $_REQUEST['section'] ) );
    		//if($current_tab == 'payment_gateways' && $current_section!=''){
    		if($current_tab == 'checkout' && $current_section!=''){
                $gateways = $woocommerce->payment_gateways->payment_gateways();
                foreach($gateways as $gateway){
    				if(strtolower(get_class($gateway))==$current_section){
    					$current_gateway = $gateway -> id;
                        $extra_charges_id = 'woocommerce_'.$current_gateway.'_extra_charges';
                        $extra_charges_type = $extra_charges_id.'_type';
                        if(isset($_REQUEST['save'])){
                            echo  $extra_charges_id."\n";
    						echo $extra_charges_type."\n";
    						update_option( $extra_charges_id, $_REQUEST[$extra_charges_id] );
                            update_option( $extra_charges_type, $_REQUEST[$extra_charges_type] );
                        }
                        $extra_charges = get_option( $extra_charges_id);
                        $extra_charges_type_value = get_option($extra_charges_type);
    
                    }
                }
    
                ?>
                <script>
                jQuery(document).ready(function($){
                    $data = '<h4>Add Extra Charges</h4><table class="form-table">';
                    $data += '<tr valign="top">';
                    $data += '<th scope="row" class="titledesc">Extra Charges</th>';
                    $data += '<td class="forminp">';
                    $data += '<fieldset>';
                    $data += '<input style="" name="<?php echo $extra_charges_id?>" id="<?php echo $extra_charges_id?>" type="text" value="<?php echo $extra_charges?>"/>';
                    $data += '<br /></fieldset></td></tr>';
                    $data += '<tr valign="top">';
                    $data += '<th scope="row" class="titledesc">Extra Charges Type</th>';
                    $data += '<td class="forminp">';
                    $data += '<fieldset>';
                    $data += '<select name="<?php echo $extra_charges_type?>"><option <?php if($extra_charges_type_value=="add") echo "selected=selected"?> value="add">Total Add</option>';
                    $data += '<option <?php if($extra_charges_type_value=="percentage") echo "selected=selected"?> value="percentage">Total % Add</option>';
                    $data += '<br /></fieldset></td></tr></table>';
                    $('.form-table:last').after($data);
    
                });
    </script>
    <?php
    }
    }

    Tell me if u encounter some issues.

  6. Dalibr
    Member
    Posted 5 months ago #

    Thank you so much aaarghhh, it works!

  7. mamatobaby
    Member
    Posted 5 months ago #

    I just updated the plugin so it works with the new woocommerce update, but the formulation I'm using 5% rounds up (from .60 to 1.00) when adding on to an order. Is it supposed to be that way? Thanks.

  8. mamatobaby
    Member
    Posted 5 months ago #

    It's also not adding that fee when checking out and going to paypal.

  9. mokarrako
    Member
    Posted 5 months ago #

    I have the sema problem too, with this function dont aply the fee, then when i try to go to paypal dont works. Aaarghhh PLEASE HELP!!

  10. rod_lee
    Member
    Posted 5 months ago #

    hi mamatobaby & mokarrako,

    Are you all using percentage for paypal?

  11. mamatobaby
    Member
    Posted 5 months ago #

    No, I looked into it and it's actually against the terms and conditions of PayPal to charge/penalize your customer for choosing PayPal as the payment method.

  12. rod_lee
    Member
    Posted 5 months ago #

    Hi mamatobaby,

    I made a change on one of the function in "woocommerce-add-extra-charges-option-to-payment-gateways.php" and it seems to work with the paypal percentage. Maybe you can try this and see if it works:

    public function calculate_totals( $totals ) {
        global $woocommerce;
        $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
        $current_gateway = '';
        if ( ! empty( $available_gateways ) ) {
               // Chosen Method
            if ( isset( $woocommerce->session->chosen_payment_method ) && isset( $available_gateways[ $woocommerce->session->chosen_payment_method ] ) ) {
                $current_gateway = $available_gateways[ $woocommerce->session->chosen_payment_method ];
            } elseif ( isset( $available_gateways[ get_option( 'woocommerce_default_gateway' ) ] ) ) {
                $current_gateway = $available_gateways[ get_option( 'woocommerce_default_gateway' ) ];
            } else {
                $current_gateway =  current( $available_gateways );
    
            }
        }
        if($current_gateway!=''){
            $current_gateway_id = $current_gateway -> id;
            $extra_charges_id = 'woocommerce_'.$current_gateway_id.'_extra_charges';
            $extra_charges_type = $extra_charges_id.'_type';
            $extra_charges = (float)get_option( $extra_charges_id);
            $extra_charges_type_value = get_option( $extra_charges_type);
            if($extra_charges){
                if($extra_charges_type_value=="percentage"){
                    //$totals -> cart_contents_total = $totals -> cart_contents_total + round(($totals -> cart_contents_total*$extra_charges)/100);
                    $totals -> cart_contents_total = $totals -> cart_contents_total + round(($totals -> cart_contents_total*$extra_charges)/100, 1, PHP_ROUND_HALF_UP);
               }else{
                    $totals -> cart_contents_total = $totals -> cart_contents_total + $extra_charges;
                }
                $this -> current_gateway_title = $current_gateway -> title;
                $this -> current_gateway_extra_charges = $extra_charges;
                $this -> current_gateway_extra_charges_type_value = $extra_charges_type_value;
                add_action( 'woocommerce_review_order_before_order_total',  array( $this, 'add_payment_gateway_extra_charges_row'));
    
            }
    
        }
        return $totals;
    }
  13. mokarrako
    Member
    Posted 5 months ago #

    if to make a charge to the customer for choosing PayPal is against the terms and conditions of PayPal we can make a discount if the customer choose other method, simply. But is there any plugin for discounts charges to payment method? F***ING PayPal!

  14. mokarrako
    Member
    Posted 5 months ago #

    rod_lee yes i was using a percentage for Paypal, ill try your function. Thanks!!

  15. jade.stewart
    Member
    Posted 3 months ago #

    I tryed adding the code `function add_form_fields(){

    global $woocommerce;
             // Get current tab/section
            $current_tab        = ( empty( $_GET['tab'] ) ) ? '' : sanitize_text_field( urldecode( $_GET['tab'] ) );
            $current_section    = ( empty( $_REQUEST['section'] ) ) ? '' : sanitize_text_field( urldecode( $_REQUEST['section'] ) );
    		//if($current_tab == 'payment_gateways' && $current_section!=''){
    		if($current_tab == 'checkout' && $current_section!=''){
                $gateways = $woocommerce->payment_gateways->payment_gateways();
                foreach($gateways as $gateway){
    				if(strtolower(get_class($gateway))==$current_section){
    					$current_gateway = $gateway -> id;
                        $extra_charges_id = 'woocommerce_'.$current_gateway.'_extra_charges';
                        $extra_charges_type = $extra_charges_id.'_type';
                        if(isset($_REQUEST['save'])){
                            echo  $extra_charges_id."\n";
    						echo $extra_charges_type."\n";
    						update_option( $extra_charges_id, $_REQUEST[$extra_charges_id] );
                            update_option( $extra_charges_type, $_REQUEST[$extra_charges_type] );
                        }
                        $extra_charges = get_option( $extra_charges_id);
                        $extra_charges_type_value = get_option($extra_charges_type);
    
                    }
                }
    
                ?>
                <script>
                jQuery(document).ready(function($){
                    $data = '<h4>Add Extra Charges</h4><table class="form-table">';
                    $data += '<tr valign="top">';
                    $data += '<th scope="row" class="titledesc">Extra Charges</th>';
                    $data += '<td class="forminp">';
                    $data += '<fieldset>';
                    $data += '<input style="" name="<?php echo $extra_charges_id?>" id="<?php echo $extra_charges_id?>" type="text" value="<?php echo $extra_charges?>"/>';
                    $data += '<br /></fieldset></td></tr>';
                    $data += '<tr valign="top">';
                    $data += '<th scope="row" class="titledesc">Extra Charges Type</th>';
                    $data += '<td class="forminp">';
                    $data += '<fieldset>';
                    $data += '<select name="<?php echo $extra_charges_type?>"><option <?php if($extra_charges_type_value=="add") echo "selected=selected"?> value="add">Total Add</option>';
                    $data += '<option <?php if($extra_charges_type_value=="percentage") echo "selected=selected"?> value="percentage">Total % Add</option>';
                    $data += '<br /></fieldset></td></tr></table>';
                    $('.form-table:last').after($data);
    
                });
    </script>
    <?php
    }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    but it crashed out the site

  16. rod_lee
    Member
    Posted 3 months ago #

    Hi jade.stewart,

    Try using another plugin call "WooCommerce Pay for Payment"

Reply

You must log in to post.

About this Plugin

About this Topic