• I’ve search the internet for a solutions but haven’t found THE solution. What I want is to add an additional fee/surcharge on a per product base. For example;

    Product A:
    Price – € 100,-
    Fee – € 10,-

    Product B:
    Price – € 250,-
    Fee – € 25,-

    etc…

    Is it possible to add the fee through the admin and place it in the cart total? I’ve found this code

    /**
    	 * Add a fixed surcharge to your cart / checkout based on products in cart
    	 * Taxes, shipping costs and order subtotal are all included in the surcharge amount
    	 *
    	 * Change $fixed to set the surcharge to a value to suit
    	 *
    	 * Change in_array to !in_array to EXCLUDE the $countries array from surcharges
    	 *
    	 * Uses the WooCommerce fees API
      	 * Add to theme functions.php
    	 */
    	add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
    	function woocommerce_custom_surcharge() {
    		global $woocommerce;
    
    		if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    			return;
    
    		// Setup an array or products that have a surcharge applied
    		// eg $setupfee_array = array( '7246' );
    		// or $setupfee_array = array( '7246','7500','4567' );
    		$setupfee_array = array( '7246' );
    
    		// The fee
    		$fixed = 5.00;
    
    		// loop through the cart looking for the free shpping products
    		foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
    
    			if( in_array( $values['product_id'], $setupfee_array ) ) {
    				$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) + $fixed;
    				$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, 'standard' );
    			}
    
    		}
    
    	}

    That’s working but I’ve got a lot of products and it would be great if I can fill in the amount of the fee in the admin instead of use php codes.

  • The topic ‘(WooCommerce) Add additional fee/surcharge’ is closed to new replies.