Changing a product's Tax Category ID onSaveProduct event I'm trying to alter a products tax category whenever it's saved based on a condition.

craft()-&gt;on('commerce_products.onSaveProduct', function(Event $event){
    $product = $event-&gt;params['product'];
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;id = $product-&gt;productFilterArtist[0]-&gt;id;
    $artist = $criteria-&gt;first();

    //Craft::dd($product-&gt;taxCategoryId); // 2

    if ($artist-&gt;getContent()-&gt;vatRegistered) {
        $product-&gt;taxCategoryId = 1;
        //Craft::dd($product-&gt;taxCategoryId); // 1
    }

    $success = craft()-&gt;elements-&gt;saveElement($product);

    //Craft::dd($product-&gt;taxCategoryId); // 1
});


It appears to work as the output of each Craft::dd is correct. However the entry still shows the original tax category in the CP.

I have been able to alter the shipping category in the same way without trouble. Am I missing something?
Setting the new field value onSaveProduct meant that the only the general element and its custom field data was being saved and not the tax ID on the product model.

To solve this, the onBeforeSaveProduct event should be used. This allows modification of the product model before it's saved.

craft()-&gt;on('commerce_products.onBeforeSaveProduct', function(Event $event){
    $product = $event-&gt;params['product'];
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;id = $product-&gt;productFilterArtist[0]-&gt;id;
    $artist = $criteria-&gt;first();
    if ($artist &amp;&amp; $artist-&gt;getContent()-&gt;vatRegistered) {
        $product-&gt;taxCategoryId = 1;
    }
})