Black Friday Sale
Up to 30% off Acowebs WordPress plugins · Ends 4 Dec
01d10h19m55s
View deals
Hi, How can we help?

Esc to close

Add additional fee for deposit selection

Updated Plugin version 4.3.0 1 min read

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. 

Was this article helpful?

Still need help?

Our support team can help with setup, settings and anything these guides don't cover.