Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save plugin-republic/88bd906c74f83d389763335c2d2b83dd to your computer and use it in GitHub Desktop.

Select an option

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
<?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