1/** 2 * Cart & Checkout Block Interop 3 */ 4 5(function() { 6 7 if (!window.wc || !window.wc.blocksCheckout || !window.wp || !window.wp.data) { 8 return; 9 } 10 11 const {registerCheckoutFilters} = window.wc.blocksCheckout; 12 13 registerCheckoutFilters('rp-wcdpd-virtual-coupon-labels', { 14 15 coupons: (coupons, context) => { 16 17 // Fetch full cart data 18 const cartData = window.wp.data.select('wc/store/cart').getCartData(); 19 20 // Map through coupons and apply labels 21 return coupons.map((coupon) => { 22 23 // Get custom label 24 const custom_label = ( 25 cartData && 26 cartData.extensions && 27 cartData.extensions.rp_wcdpd_virtual_coupon_data && 28 cartData.extensions.rp_wcdpd_virtual_coupon_data.labels 29 ) ? cartData.extensions.rp_wcdpd_virtual_coupon_data.labels[coupon.code] : null; 30 31 // Check if label exists 32 if (custom_label) { 33 var new_coupon = Object.assign({}, coupon); 34 new_coupon.label = custom_label; 35 return new_coupon; 36 } 37 38 return coupon; 39 }); 40 } 41 }); 42 43})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.