WordPress.org

Forums

[resolved] Adding fee for each cart item (3 posts)

  1. cybermatrixmedia
    Member
    Posted 1 year ago #

    I'm using a paypal snippet to add a processing fee at checkout but i was wondering if there was a way to add the processing fee for each product added to the shopping cart.

    function woo_add_cart_fee() {
    
    	global $woocommerce;
    
    	if ( is_cart() ) {
    
    		$woocommerce->cart->add_fee( __('Processing', 'woocommerce'), 3 );
    
    	}
    
    }
    
    add_action( 'woocommerce_before_cart_table', 'woo_add_cart_fee' );

    Any help is appreciated.

  2. cybermatrixmedia
    Member
    Posted 1 year ago #

    nevermind. a few hours of searching but I found it.

    /**
     * Add a 1% surcharge to your cart / checkout
     * change the $percentage to set the surcharge to a value to suit
     * 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;
    
    	$percentage = 0.01;
    	$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
    	$woocommerce->cart->add_fee( 'Surcharge', $surcharge, true, 'standard' );
    
    }
  3. cybermatrixmedia
    Member
    Posted 1 year ago #

    Solved & Resolved

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags