php - Add Tip input by customer to woocommerce checkout page -
i developing food ordering woocommerce store. trying add input field or grouped button let customer add delivery tips checkout total.
backend part: wrote action add tip checkout based on percentage given (let's 10% of total order)
add_action( 'woocommerce_cart_calculate_fees', 'calculatetipspercentage', 10, 1 ); function calculatetipspercentage( $cart ) { if ( is_admin() && ! defined( 'doing_ajax' ) ) return; $total_tax = 0; $carttotal= 0; // unformated taxes array $taxes = $cart->get_taxes(); //get tax amount taxes array foreach($taxes $tax) $total_tax += $tax; global $woocommerce; $percentage = 0.10;//percentage of tips (must entered customer) $carttotalamount = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ); //cart total without tax $totalorderwithtax = ( $carttotalamount + $total_tax); //cart total tax $extrafee= round( $totalorderwithtax * $percentage, 2 ); //extra fee amount $percetagetoshow = ( $percentage * 100 ); $woocommerce->cart->add_fee( "tip ({$percetagetoshow}%)", $extrafee, true, '' ); }
my problem front-end part.
how can add kind of input field button (add tips checkout) let customer add percentage , click button fire action found above. or if can through ajax/jquery without button (without refreshing page) better.
any appreciated.
Comments
Post a Comment