Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function woo_add_cart_fee() {
- global $woocommerce;
- $items = $woocommerce->cart->get_cart();
- $restaurant = array();
- foreach($items as $item => $values) {
- $restaurant_list_ids = wp_get_post_terms($values['data']->get_id(),'product_cat',array('fields'=>'ids')); // we assumed that restaurant belongs to product_cat
- if($restaurant_list_ids){
- foreach ($restaurant_list_ids as $id) {
- if(!in_array($id, $restaurant)){
- $restaurant[] = $id;
- }
- }
- }
- }
- $restaurant_multiply = count($restaurant) - 1; // first restaurant id free
- $extra_fee = 2; // 2 euro
- $woocommerce->cart->add_fee( __('Extra fees', 'woocommerce'), $extra_fee*$restaurant_multiply );
- }
- add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement