woocommerce / woocommerce-accommodation-bookings

An accommodations add-on for the WooCommerce Bookings extension.
87 stars 31 forks source link

Missing block count cost modifier #404

Closed axi closed 6 months ago

axi commented 6 months ago

This is kind of an issue that these feature is missing but I leave this more as a potential lead for someone searching a way to have discounts for many nights booked.

We can manually add pricing rules (no way through interface) using this:

add_action(
    hook_name:'woocommerce_product_get_pricing',
    callback: [$this, 'addPricingRuleForLength'],
    accepted_args: 2
);
public function addPricingRuleForLength($values, \WC_Product_Accommodation_Booking $product): array
{
    $priceReduced = 20;
    $values[] = [
        'type' => 'blocks',
        'cost' => $priceReduced,
        'modifier' => 'equals',
        'base_cost' => '',
        'base_modifier' => '',
        'from' => 8, // inclusive
        'to' => 30  // inclusive
    ];

    return $values;
}

Rules are well taken into account :-)