This small snippet came out of a problem with the tax calculation for value vouchers created through the WooCommerce plugin “Ultimate Gift Cards for WooCommerce” and Germanized. Because of the way the two plugins handle coupons, it was not possible to apply the tax calculation at the time of redemption. The only option was to deduct the tax from the sold voucher during payment, which is of course not ideal if you sell products from several tax classes. If you use the combination of both plugins described above in your shop, the snippet solves the problem.
Are you looking for a professional online shop or do you need help from a specialist? Get in touch with me! You can find more about my services for online shops here. Online shop development in Vienna - OSULZER.AT
/**
*
* Set the bought coupon to apply tax when redeemed
* @param $order_id
* @param $item_id
* @param $new_coupon_id
* @param $product_id
* @return void
*/
function osu_setCouponBeforeTax( $order_id, $item_id, $new_coupon_id, $product_id ) {
// Load the coupon object
$coupon = new WC_Coupon($new_coupon_id);
update_post_meta($new_coupon_id, 'is_voucher', 'yes');
}
add_action('wps_wgm_set_coupon_meta_for_product_as_a_gift', 'osu_setCouponBeforeTax', 1, 4 );
Learn more about my services as a WooCommerce developer.




