• Hello

    We have customized our WooCommerce checkout page to include certain add-ons as fees in the cart. We use the woocommerce_cart_calculate_fees hook to add these fees. However, when processing payments through PayPal, we notice that PayPal is using the cart subtotal amount instead of the order total amount. Is there a setting to change this behavior, or is there a hook we can use to ensure PayPal picks up the order total instead of the cart subtotal?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Krystian from Syde

    (@inpsydekrystian)

    Hello @nomangardazi

    To better assist you, could you please share the snippet of code where you are using the to add the fees?

    In the meantime, here is a general example of how you might modify it. This example uses the same hook to apply a surcharge directly within WooCommerce which reflects correctly in the PayPal popup.

    add_action( 'woocommerce_cart_calculate_fees', 'woocommerce_custom_surcharge' );
    function woocommerce_custom_surcharge() {
      global $woocommerce;
    	
      if ( ! is_checkout() && ! defined( 'WOOCOMMERCE_CHECKOUT' ) )
        return;
    
      $percentage = 0.75; // Set the surcharge percentage here
      $surcharge = ($woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total) * $percentage;	
      $woocommerce->cart->add_fee('Surcharge', $surcharge, true, '');
    }
    

    Looking forward to your response so we can assist you further.

    Kind Regards,

    Krystian

    Hello Syde,

    Thank you for your response. On behalf of Noman, I am sharing the code below. Please feel free to let us know if you need any further information to help us resolve this challenge. Looking forward to your support.

    
    add_action( 'woocommerce_cart_calculate_fees', array( $this, 'include_addon_service_fees' ) );
    
    /**
    
    * Add fees for add on services.
    
    *
    
    * @param object $cart cart object for the particular order.
    
    * @return void
    
    */
    
    public function include_addon_service_fees( $cart ) {
    
    ...
    
    $product = wc_get_product( $product_id );
    
    if ( $product->is_type( 'simple' ) ) {
    
    $value = intval( $product->get_meta( 'custom_property_id_field' ) );
    
    $extra_charges_per_guest = intval( $product->get_meta( 'extra_charges_per_guest' ) );
    
    $extra_starts_at = intval( $product->get_meta( 'extra_charges_starting_at' ) );
    
    $quantity = $cart_item['quantity'];
    
    break;
    
    }
    
    }
    
    // Get discount amount based on coupon.
    
    // Select the addons that have been checked by the user.
    
    $selected_add_ons = array_filter(
    
    $post_data,
    
    function ( $key ) {
    
    return strpos( $key, '_custom_checkbox_' ) === 0;
    
    },
    
    ARRAY_FILTER_USE_KEY
    
    );
    
    $adults = isset( $post_data['_number_of_adults'] ) ?
    
    intval( $post_data['_number_of_adults'] ) :
    
    0;
    
    $total_guests = $adults + ( isset( $post_data['_number_of_kids'] ) ? intval( $post_data['_number_of_kids'] ) : 0 );
    
    // Check if the number of adults is more than 2.
    
    if ( $adults > 2 ) {
    
    ... ' Error message here '
    return;
    
    }
    
    // Checks whether the prices include taxes or is exclusive of taxes.
    
    $prices_include_tax = get_option( 'woocommerce_prices_include_tax' );
    
    ...
    
    // Adds the extra guest fees based on the set value in the meta field ( extra_charges_starting_at )
    
    // not in Smoobu as we were having troule getting this extra guest charges from Smoobu.
    
    if (
    
    ! empty( $extra_charges_per_guest ) &&
    
    ! empty( $extra_starts_at ) &&
    
    $total_guests >= $extra_starts_at
    
    ) {
    
    // $guest_fee = ( $total_guests - $extra_starts_at + 1 ) * $extra_charges_per_guest * ( 1 - $discount_percentage );
    
    $guest_fee = ( $total_guests - $extra_starts_at + 1 ) * $extra_charges_per_guest * $quantity;
    
    ...
    
    ...
    
    $cart->add_fee( $guest_key, floatval( $guest_fee ), $taxable, $tax_class );
    
    }
    
    if ( ! empty( $selected_add_ons ) ) {
    
    foreach ( $selected_add_ons as $key => $value ) {
    
    $addon_key = substr( strrchr( $key, '_' ), 1 );
    
    $add_on_price = floatval( sanitize_text_field( $post_data[ '_custom_addon_price_' . $addon_key ] ) );
    
    $add_on_name = sanitize_text_field( $post_data[ '_custom_addon_name_' . $addon_key ] );
    
    $add_on_type = sanitize_text_field( $post_data[ '_custom_addon_type_' . $addon_key ] );
    
    $addon_tax_class = ( 'no' === $is_property_owned ) ? 'Zero rate' : 'Addon';
    
    switch ( intval( $add_on_type ) ) {
    
    case 0:
    
    $total_fee = floatval( $add_on_price );
    
    $multiplier = 1;
    
    break;
    
    case 1:
    
    ...
    
    break;
    
    case 2:
    
    ...
    
    break;
    
    case 3:
    
    ...
    
    break;
    
    case 4:
    
    ...
    
    break;
    
    case 5:
    
    $guest_count = isset( $post_data[ '_include_kids_checkbox_' . $addon_key ] ) && $post_data[ '_include_kids_checkbox_' . $addon_key ] ?
    
    intval( $total_guests ) :
    
    intval( $adults );
    
    $total_fee = $guest_count * floatval( $quantity ) * floatval( $add_on_price );
    
    $multiplier = $guest_count * floatval( $quantity );
    
    break;
    
    }
    
    // $total_fee *= ( 1 - $discount_percentage );
    
    // Add the fee to the cart with the appropriate tax class.
    
    $cart->add_fee( $multiplier . ' x ' . $add_on_name . '__' . $addon_key, floatval( $total_fee ), ! $taxable, $addon_tax_class );
    
    }
    
    }
    
    }
    
    
    Thread Starter nomangardazi

    (@nomangardazi)

    Hello Syde,
    Thanks for your response.
    We have used same hook and Nishit has commented the code already. He did checkout customization for us.
    It is worth mentioning here that other payment gateways including Bank transfer and Stripe are taking correct total.
    Only paypal takes subtotal when it opens a new window to pay. Other payment gateways work fine.

    Plugin Support Krystian from Syde

    (@inpsydekrystian)

    Hello @nomangardazi

    Could you please provide a sample of the code? Once we have the code, we can look into this more thoroughly and give you a solution or further guidance.

    If you do not wish to share this information publicly, we suggest you contact us directly for further assistance. You can open a ticket with our service desk. Here’s how you can request support:?Request Support. Please make sure to include the URL of this thread in your ticket for reference.

    Kind regards,
    Krystian

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.