I am trying to add Extra Fee in the total of cart/order amount only if this is first order of Customer.
I searched a lot online but I still did not find any specific solution yet.
Please someone suggest/guide the best solution to perferm this.
Thanks
You use the cart class’
add_fee()
method to add a fee. There’s no built-in way to know how many orders a customer has made, so we can try to track that via a user meta field called_number_order
.If we don’t actually update the
_number_orders
key, then it will always be null/empty/zero and the user will always be charged the first time fee. So we can try to update that key when the user completes payment.This is totally untested, so use at your own risk. Also, you might want to look into changing the number of orders total in case of refunds/cancellations, etc, but this seems like the general gist.