Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackeryfretty/ebe707a98ca0a3499e93af9b381eb7a3 to your computer and use it in GitHub Desktop.
Save zackeryfretty/ebe707a98ca0a3499e93af9b381eb7a3 to your computer and use it in GitHub Desktop.
Replace 'widget.id' with your actual widget id.
// 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