Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('woocommerce_package_rates', function($rates, $package) {
- foreach ($rates as $rate_id => $rate) {
- if ('flat_rate' === $rate->method_id) {
- $item_count = WC()->cart->get_cart_contents_count();
- if ($item_count == 1) {
- $rates[$rate_id]->cost = 10; // Flat price for 1 item
- } elseif ($item_count >= 2) {
- $rates[$rate_id]->cost = 15; // Flat price for 2 or more items
- }
- }
- }
- return $rates;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement