Created
April 15, 2025 15:55
-
-
Save zackeryfretty/ebe707a98ca0a3499e93af9b381eb7a3 to your computer and use it in GitHub Desktop.
Replace 'widget.id' with your actual widget id.
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
// Hide Free Cases if Subscription in Cart | |
function hideWidgetIfSubscription() { | |
let subscription_exists = false; | |
const rebuy_widget = window.Rebuy.widgets.find(widget => widget.id === "161420"); | |
const cart_items = Rebuy.SmartCart.items(); | |
// Use some to check for subscription existence | |
subscription_exists = cart_items.some(item => item.product.subscription === true); | |
// Check if the widget exists before trying to hide it | |
if (rebuy_widget && subscription_exists) { | |
rebuy_widget.hide(); | |
} else if (rebuy_widget) { | |
rebuy_widget.show(); | |
} | |
} | |
// Run on page load | |
hideWidgetIfSubscription(); | |
// Run on each cart change | |
document.addEventListener('rebuy:cart.change', hideWidgetIfSubscription); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment