CMS Mastering Development Wordpress

How to add linked product to cart via AJAX in woocommerce?

I have eCommerce website. And I’m using this code example to add products to cart with ajax: Everything is working with simple and variable products. But how can I expand this code to also add linked products to cart if they are checked?