Created
November 22, 2019 14:09
-
-
Save rjehangir/00ab863d6e9d9899873cdcc399694510 to your computer and use it in GitHub Desktop.
Woo-CP-Javascript-Data-Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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