Discount code for guests

Hi,

On my website, I would like to allow hosts to be paid directly online by travelers or to be able to handle payments themselves (in which case there wouldn’t be any payment on my site, just a reservation).
Since I couldn’t find a simple solution for this with WooCommerce + HivePress, I’ve come up with a workaround for “manual” payment. It involves manually creating a 100% discount code dedicated to the host’s listings. The host can then provide this code to guests renting their properties.
My issue is that when I apply the code: if the host has added extras to their listing, these are not included in the discount, and there is still a remainder to be paid, making the rental still payable, since WooCommerce calculates the discount before tax.

I’ve tested this code, but it generates 503 errors; maybe I am doing something wrong. Could you help me?

function adjust_coupon_discount_to_total($discount, $discounting_amount, $cart_item, $single, $coupon) {
    if (is_admin() && !defined('DOING_AJAX')) {
        return $discount;
    }
    if (is_object($coupon) && $coupon->is_type('percent') && isset(WC()->cart) && !WC()->cart->is_empty()) {
        WC()->cart->calculate_totals();
        $total = WC()->cart->get_total('edit');
        if (is_numeric($total)) {
            $amount = floatval($coupon->get_amount());
            $discount = ($amount * $total) / 100;
        }
    }

    return $discount;
}

add_filter('woocommerce_coupon_get_discount_amount', 'adjust_coupon_discount_to_total', 10, 5);

Hi,

Unfortunately, we cannot help with customization, as it is not within the scope of our support. As a workaround, we recommend using the existing discount feature: How to enable discounts for bookings - HivePress Help Center

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.