Skip to content

Instantly share code, notes, and snippets.

@rjehangir
Created November 22, 2019 14:09
Show Gist options
  • Save rjehangir/00ab863d6e9d9899873cdcc399694510 to your computer and use it in GitHub Desktop.
Save rjehangir/00ab863d6e9d9899873cdcc399694510 to your computer and use it in GitHub Desktop.
Woo-CP-Javascript-Data-Example
/**
* Triggers an action when the total price of a composite product changes
*
*/
;( function ( $, window, document, undefined ) {
$( '.composite_data' )
.on( 'wc-composite-initializing', function( event, composite ) {
var obj = composite.api;
composite.actions.add_action( 'composite_totals_changed', function(){onCompositeTotalsChanged(obj);}, 100, obj);
} );
} ) ( jQuery, window, document );
/**
* Adjusts the page content when the composite total is changed.
*
*/
function onCompositeTotalsChanged(obj){
// In here I want to access the 'sku' field that was added with the PHP 'woocommerce_composited_product_data' filter.
// I've tried looking in the following objects:
console.log(obj.get_components()); // Searched through this in the Chrome inspector but can't find 'sku'
console.log(components[0].get_selected_product_meta(false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment