Created
November 19, 2026 12:27
-
-
Save plugin-republic/88bd906c74f83d389763335c2d2b83dd to your computer and use it in GitHub Desktop.
Bookings for WooCommerce: flat rate for the first 4 days, then +5% of the standard price per extra day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Bookings for WooCommerce: flat rate for the first 4 days, then each extra day adds 5% of the standard price. | |
| * | |
| * Setup: tick Flat rate on the product, set the Standard price, and remove any Discounts rows. | |
| * Example with a standard price of 10: 1-4 days = 10.00, 5 days = 10.50, 8 days = 12.00 | |
| */ | |
| add_filter( 'bfwc_discount_rates', function( $discounts, $product_id ) { | |
| if ( ! bfwc_is_flat_rate( $product_id ) ) { | |
| return $discounts; | |
| } | |
| $std_price = (float) get_post_meta( $product_id, '_std_booking_cost', true ); | |
| if ( $std_price <= 0 ) { | |
| return $discounts; | |
| } | |
| return array( | |
| array( | |
| 'rate' => -1 * $std_price * 0.05, // a negative per-day discount works as a surcharge | |
| 'type' => 'perunit', | |
| 'after' => 4, // number of days included in the flat rate | |
| 'from' => 'partial', // only charge the days after the 4th | |
| ), | |
| ); | |
| }, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment