Advertisement
drkskwlkr

Custom Flat Rate pricing (1 item for $10, 2 or more items for $15)

Jun 10th, 2024
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | Source Code | 0 0
  1. add_filter('woocommerce_package_rates', function($rates, $package) {
  2.     foreach ($rates as $rate_id => $rate) {
  3.         if ('flat_rate' === $rate->method_id) {
  4.             $item_count = WC()->cart->get_cart_contents_count();
  5.            
  6.             if ($item_count == 1) {
  7.                 $rates[$rate_id]->cost = 10; // Flat price for 1 item
  8.             } elseif ($item_count >= 2) {
  9.                 $rates[$rate_id]->cost = 15; // Flat price for 2 or more items
  10.             }
  11.         }
  12.     }
  13.  
  14.     return $rates;
  15. }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement