PageSourceSearch

https://activewoo.com/wp-content/plugins/subscriptions-for-woocomm…/wc-block/cart-line-items.js?ver=1789747648

js activewoo.com collected 2026-10-04 14:00:10 UTC 4,946 bytes, 161 lines download raw bytes

1jQuery(function($){
2	if ( ! window.wc ) {
3		return;
4	}
5	if ( typeof window.sfw_public_block === 'undefined' || typeof window.sfw_public_param === 'undefined' ) {
6		return;
7	}
8	if ( ! window.wc.blocksCheckout || ! window.wc.blocksCheckout.registerCheckoutFilters ) {
9		return;
10	}
11
12	var registerCheckoutFilters = window.wc.blocksCheckout.registerCheckoutFilters;
13	var cartItemRequestCache = {};
14	var cartItemRequestPending = {};
15
16	function getArgsContext( args ) {
17		return ( args && args.context ) ? args.context : '';
18	}
19
20	function getCartItemData( args ) {
21		return ( args && args.cartItem && args.cartItem.item_data ) ? args.cartItem.item_data : null;
22	}
23
24	function wpsSfwmodifySubtotalPriceFormat( defaultValue, extensions, args ) {
25		var isCartContext = ( getArgsContext( args ) === 'cart' );
26		if ( ! isCartContext ) {
27			return defaultValue;
28		}
29
30		var cartItem = getCartItemData( args );
31		if ( ! cartItem ) {
32			return defaultValue;
33		}
34
35		var sfwPrice = cartItem.find( function( item ) {
36			return item && item.name === 'wps-sfw-price-html';
37		} );
38
39		if ( sfwPrice && typeof sfwPrice.value !== 'undefined' && sfwPrice.value !== '' ) {
40			return defaultValue + ' ' + sfwPrice.value;
41		}
42
43		return defaultValue;
44	}
45
46	function applyAttachedProductsUI( attachedProducts, cartBoxIndex ) {
47		if ( ! attachedProducts || ! attachedProducts.length ) {
48			return;
49		}
50
51		if ( jQuery('.wps_show_customer_subscription_box_popup').length > 0 ) {
52			return;
53		}
54
55		var attachedProductsHtml = '<div class="wps-attached-products-popup"><strong>Attached Products:</strong><ul>';
56		for ( var i = 0; i < attachedProducts.length; i++ ) {
57			var product = attachedProducts[i];
58			if ( ! product ) {
59				continue;
60			}
61			attachedProductsHtml += '<li><img src="' + product.image + '" width="40" height="40" />' + product.name + ' x ' + product.quantity + '</li>';
62		}
63		attachedProductsHtml += '</ul><span class="wps_sfw_customer_close_popup" style="cursor: pointer;">&times;</span></div>';
64
65		var viewLabelHTML = '<a href="#" class="wps_show_customer_subscription_box_popup">View Attached Products</a>' + attachedProductsHtml;
66
67		var containers = [
68			jQuery(".wc-block-components-order-summary-item").eq( cartBoxIndex ).find('.wc-block-components-product-name'),
69			jQuery(".wc-block-cart-items__row").eq( cartBoxIndex ).find('.wc-block-cart-item__prices')
70		];
71
72		for ( var c = 0; c < containers.length; c++ ) {
73			var container = containers[c];
74			if ( container && container.length ) {
75				container.after( viewLabelHTML );
76			}
77		}
78	}
79
80	function wpsWspmodifyCartItemPrice( defaultValue, extensions, args ) {
81		var ctx = getArgsContext( args );
82		var isCartContext = ( ctx === 'cart' || ctx === 'summary' );
83		if ( ! isCartContext ) {
84			return defaultValue;
85		}
86
87		var cartItem = getCartItemData( args );
88		if ( ! cartItem ) {
89			return defaultValue;
90		}
91
92		var cartkey = cartItem.find( function( item ) {
93			return item && item.name === 'wps_sfw_subscription_box_cart_key';
94		} );
95		var cartIndex = cartItem.find( function( item ) {
96			return item && item.name === 'wps_sfw_subscription_box_cart_index';
97		} );
98
99		if ( cartkey && cartIndex && cartkey.value ) {
100			var cartKey = cartkey.value;
101			var cartBoxIndex = parseInt( cartIndex.value, 10 );
102
103			if ( cartItemRequestCache.hasOwnProperty( cartKey ) ) {
104				applyAttachedProductsUI( cartItemRequestCache[ cartKey ], cartBoxIndex );
105				return defaultValue;
106			}
107
108			if ( cartItemRequestPending.hasOwnProperty( cartKey ) ) {
109				return defaultValue;
110			}
111
112			cartItemRequestPending[ cartKey ] = true;
113			jQuery.ajax({
114				url: sfw_public_block.ajaxurl,
115				type: "POST",
116				data: {
117					action: "wps_get_cart_item",
118					cart_key: cartKey,
119					nonce: sfw_public_param.sfw_public_nonce
120				},
121				success: function (response) {
122					var attachedProducts = [];
123					if ( response && response.success && response.data && response.data.attached_products ) {
124						attachedProducts = response.data.attached_products;
125					}
126					cartItemRequestCache[ cartKey ] = attachedProducts;
127					delete cartItemRequestPending[ cartKey ];
128					applyAttachedProductsUI( attachedProducts, cartBoxIndex );
129				},
130				error: function () {
131					delete cartItemRequestPending[ cartKey ];
132				}
133			});
134
135			return defaultValue;
136		}
137
138		var wspData = cartItem.find( function( item ) {
139			return item && item.name === 'wps-wsp-switch-direction';
140		} );
141
142		if ( wspData && typeof wspData.value !== 'undefined' && wspData.value !== '' ) {
143			return defaultValue + ' ' + wspData.value;
144		}
145
146		return defaultValue;
147	}
148
149	function modifyPlaceOrderButtonLabel( defaultValue ) {
150		if ( sfw_public_block.place_order_button_text ) {
151			return sfw_public_block.place_order_button_text;
152		}
153		return defaultValue;
154	}
155
156	registerCheckoutFilters( 'wps-sfw-checkout-block', {
157		subtotalPriceFormat: wpsSfwmodifySubtotalPriceFormat,
158		cartItemPrice: wpsWspmodifyCartItemPrice,
159		placeOrderButtonLabel: modifyPlaceOrderButtonLabel
160	} );
161});

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.