Knowledge Base

Hi, How can we help?

Add additional fee for deposit selection

This document explains how you can add an additional fee for deposit selection.

For this, first, you need to enable deposit on the checkout page.
Go to Dashboard-> Deposits-> General Settings.

Then add the following code to your theme/child-theme functions.php file.

add_action( 'woocommerce_cart_calculate_fees', 'acowebs_checkout_radio_choice_fee', 20, 1 );

function acowebs_checkout_radio_choice_fee( $cart ) {
   if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;

   $radio = WC()->session->get( 'aco_radio_chosen' );
   $total = '50'; // Deposit amount

   if ( $radio == 'deposit' ) {
      $cart->add_fee( 'Deposit  Charge', $total );
   }
}

add_action( 'woocommerce_checkout_update_order_review', 'acowebs_checkout_radio_choice_set_session' );

function acowebs_checkout_radio_choice_set_session( $posted_data ) {
   parse_str( $posted_data, $output );

   if ( isset( $output['awcdp_deposit_option'] ) ){
      WC()->session->set( 'aco_radio_chosen', $output['awcdp_deposit_option'] );
   }
}

This sample code will work on the checkout page. It adds an additional fee for the deposit if we choose to pay through the deposit. You can change the  “additional fee value” and the text ”Deposit charge” to your desired value.

Below is an example of the execution of the above code. First, add products to the cart. 

You can see an additional fee as a deposit charge of 50 (as given in the code) when the deposit is chosen. 

Customer Support

If you have questions about our plugin(s), are experiencing issues with any of our plugin