Auto adjust product tax class based on WooCommerce category

I’m trying to update the tax class based on the category being set. I need to use the Reduced Rate for everything in my category "Books". The category ID is 133, and I’m currently using this filter, but it’s not working. What am I missing here?

add_filter( 'woocommerce_new_product', 'change_tax_for_books' );

function change_tax_for_books( $id ) {
    $product = wc_get_product( $id );
    if( has_term( 133, 'product_cat', $product ) ) {
        $product->set_tax_class( 'Reduced Rate' );
    }
}

I’d like to add my WordPress is in Dutch, do I have to use "Gereduceerd Tarief" in this case?

Source: Ask PHP

LEAVE A COMMENT