How to add custom contexts to enhanced ecommerce checkout data?

In order to track the steps within the checkout process I want to use the enhanced ecommerce tracking method. The variable values should be retrieved from the corresponding data layer.

I created JSON schemas to add the custom properties ‚campaign’, ‚sale’ and ‚productType’. Both, the addEnhancedEcommerceProductContext method as well as the JSON schemas, are used to capture the details of each product included in the checkout process and therefore should be called once for each item.

Can the following code be used to loop through each item in the checkout process and to print out the product contexts as well as the custom properties for each item?

window.snowplow('addEnhancedEcommerceActionContext',   
 '<step>', // checkout step    
 '<option>' // checkout option 
);
 
window.snowplow('trackEnhancedEcommerceAction',   
 'checkout_option');
 
window.snowplow('addEnhancedEcommerceProductContext',   
 '<id>', 
 '<name>', 
 '<brand>', 
 '<category>', 
 '<variant>', 
 '<price>', 
 '<quantity>', 
 '<currencyCode>' 
);
 
window.snowplow('trackEnhancedEcommerceAction',   
  'checkout', [{
    schema: "iglu:com.example_company/ecommerce_extension_general/jsonschema/schema-version"*,
    data: {
      campaign: '<campaign name>', 
      sale:  '<sale>' 
    }   
},
{
    schema: "iglu:com.example_company/ecommerce_extension_productType/jsonschema/schema-version"*,
    data: {
      productType: '<product type>'
    }
}]);

*Schema URI needs to be replaced by final schema information.