I am developing a woocommerce store for ordering food. I am trying to add an input field or a grouped button to allow the client to add delivery tips in the total amount of the check.
Backend: I wrote an action that adds a hint to check based on a percentage (say 10% of the total)
add_action ('woocommerce_cart_calculate_fees', 'calculateTipsPercentage', 10, 1);
function calculateTipsPercentage ($ cart) {
if (is_admin () &&! defined ('DOING_AJAX'))
return
$ total_tax = 0;
$ carttotal = 0;
// Get the unformated taxes array
$ taxes = $ cart-> get_taxes ();
// get Tax amount from taxes array
foreach ($ taxes as $ tax) $ total_tax + = $ tax;
global $ woocommerce;
$ percentage = 0.10; // percentage of tips (must be entered by customer)
$ carttotalamount = ($ woocommerce-> cart-> cart_contents_total + $ woocommerce-> cart-> shipping_total); // Cart total without tax
$ totalorderwithTax = ($ carttotalamount + $ total_tax); // cart total with tax
$ extrafee = round ($ totalorderwithTax * $ percentage, 2); // extra fee amount
$ percetagetoShow = ($ percentage * 100);
$ woocommerce-> cart-> add_fee ("Tip ({$ percetagetoShow}%)", $ extrafee, true, '');
}
My problem is with the front-end part.
- ( ), , , . ajax/jquery ( ), .
.