Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function woo_add_cart_fee() {
  2. global $woocommerce;
  3. $items = $woocommerce->cart->get_cart();
  4. $restaurant = array();
  5. foreach($items as $item => $values) {
  6. $restaurant_list_ids = wp_get_post_terms($values['data']->get_id(),'product_cat',array('fields'=>'ids')); // we assumed that restaurant belongs to product_cat
  7. if($restaurant_list_ids){
  8. foreach ($restaurant_list_ids as $id) {
  9. if(!in_array($id, $restaurant)){
  10. $restaurant[] = $id;
  11. }
  12. }
  13. }
  14. }
  15. $restaurant_multiply = count($restaurant) - 1; // first restaurant id free
  16. $extra_fee = 2; // 2 euro
  17.  
  18. $woocommerce->cart->add_fee( __('Extra fees', 'woocommerce'), $extra_fee*$restaurant_multiply );
  19.  
  20. }
  21. add_action( 'woocommerce_cart_calculate_fees', 'woo_add_cart_fee' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement