How to update stock on a product variant? Setting unknown property error
Have figured it out. Need to:

use craft\commerce\elements\Variant; // not Product
setFieldValue still does not find variable stock with Variant, but set it using $variantEntry-&gt;stock = 20;
Need to find() on Variant to return the actual variant, and not
find product with variant as that returns the product

Following works, changed $productEntry to $variantEntry
use Craft;
use craft\web\Controller;
use craft\helpers\ElementHelper;
use craft\commerce\elements\Variant;

$variantEntry = Variant::find()-&gt;sku('mysku')-&gt;first();
if($variantEntry)
{
    if (!$variantEntry-&gt;hasUnlimitedStock)
    {
        $variantEntry-&gt;stock = 20;
        echo Craft::$app-&gt;elements-&gt;saveElement($variantEntry);
    }
}