I have a problem with tax settings in membership 2 pro

To apply a fixed tax to all invoices, it was suggested the following code:

add_filter( 'ms_invoice_tax_rate', 'my_custom_tax_rate', 10, 2 );

function my_custom_tax_rate( $amount, $invoice ) {
return 19.0;
}

I need to call my tax in the template, and then I need to take the tax and display it in a sum from the total amount. And I need to display my membership payment without the tax sum.

How can I do that?

  • Paul Kevin

    Hey there Alexander ,

    Hope you are well today. Kindly use the below code to apply your tax rate:

    add_filter( 'ms_invoice_tax_rate', 'my_custom_tax_rate', 10, 2 );
    add_filter( 'ms_invoice_tax_name', 'my_custom_tax_name', 10, 2 );
    
    //paypal
    add_filter( 'ms_gateway_paypalsingle_view_prepare_fields', 'my_paypal_tax_on_checkout', 99, 2 );
    
    function my_custom_tax_rate( $amount, $invoice ) {
    	return 19.0;
    }
    
    function my_custom_tax_name( $name, $invoice ) {
    	return '19.0%';
    }
    
    function my_paypal_tax_on_checkout( $fields, $invoice ) {
    	$fields['tax_rate'] = array(
    		'id' 	=> 'tax_rate',
    		'type' 	=> MS_Helper_Html::INPUT_TYPE_HIDDEN,
    		'value' => $invoice->tax_rate,
    	);
    	$fields['amount'] = array(
    		'id' 	=> 'amount',
    		'type' 	=> MS_Helper_Html::INPUT_TYPE_HIDDEN,
    		'value' => number_format( ( float ) $invoice->amount, 2, '.', '' ),
    	);
    
    	return $fields;
    }

    If you want to show the membership price with the tax amount applied, please add the following:

    add_filter( 'ms_apply_taxes', 'my_custom_tax_amount', 10, 2 );
    function my_custom_tax_amount( $amount, $membership ) {
    	$tax_rate = 19.0;
    	$tax_amount = $amount * ( $tax_rate / 100 );
    	return $amount + $tax_amount;
    }

    Warm Regards
    Paul Kevin

  • Steve

    Do I need to add just the details above or the earlier information?

    Still shows the amount entered in Membership Pro and as seen on screenshots.

    I have added (Vat rate is 20%) this to my functions.php:

    // Add Tax

    add_filter( 'ms_invoice_tax_rate', 'my_custom_tax_rate', 10, 2 );
    add_filter( 'ms_invoice_tax_name', 'my_custom_tax_name', 10, 2 );

    //paypal
    add_filter( 'ms_gateway_paypalsingle_view_prepare_fields', 'my_paypal_tax_on_checkout', 99, 2 );

    function my_custom_tax_rate( $amount, $invoice ) {
    return 20.0;
    }

    function my_custom_tax_name( $name, $invoice ) {
    return '20.0%';
    }

    function my_paypal_tax_on_checkout( $fields, $invoice ) {
    $fields['tax_rate'] = array(
    'id' => 'tax_rate',
    'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
    'value' => $invoice->tax_rate,
    );
    $fields['amount'] = array(
    'id' => 'amount',
    'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
    'value' => number_format( ( float ) $invoice->amount, 2, '.', '' ),
    );

    return $fields;
    }

    add_filter( 'ms_gateway_stripeplan_form_details_after', 'my_stripe_tax_on_checkout', 99, 2 );
    function my_stripe_tax_on_checkout( $data, $invoice ) {
    $stripe_data['tax_percent'] = 20;
    return $data;
    }

  • Steve

    The page shows the inclusive of Vat price but with no Vat shown, see attached and with this code in functions.php:

    Perhaps this is correct, the 0% rate is shown as standard for Stripe?

    // Add Tax

    add_filter( 'ms_invoice_tax_rate', 'my_custom_tax_rate', 10, 2 );
    add_filter( 'ms_invoice_tax_name', 'my_custom_tax_name', 10, 2 );

    //paypal
    add_filter( 'ms_gateway_paypalsingle_view_prepare_fields', 'my_paypal_tax_on_checkout', 99, 2 );

    function my_custom_tax_rate( $amount, $invoice ) {
    return 20.0;
    }

    function my_custom_tax_name( $name, $invoice ) {
    return '20.0%';
    }

    function my_paypal_tax_on_checkout( $fields, $invoice ) {
    $fields['tax_rate'] = array(
    'id' => 'tax_rate',
    'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
    'value' => $invoice->tax_rate,
    );
    $fields['amount'] = array(
    'id' => 'amount',
    'type' => MS_Helper_Html::INPUT_TYPE_HIDDEN,
    'value' => number_format( ( float ) $invoice->amount, 2, '.', '' ),
    );

    return $fields;
    }

    add_filter( 'ms_gateway_stripeplan_form_details_after', 'my_stripe_tax_on_checkout', 99, 2 );
    function my_stripe_tax_on_checkout( $data, $invoice ) {
    $stripe_data['tax_percent'] = 20;
    return $data;
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.