I have a “Buy Now” button on the right side of my header, so it displays at the top right throughout my site. It doesn’t make sense to me to still have a buy now button once people click it though and are in the store. Once they are in the store, I would like them to see the “Shopping Bag” & “Login bar”. I achieved this by tweaking the following code that I found in the forum:
import wixLocation from ‘wix-location’;
$w.onReady(function () {
const location = wixLocation.path.join(“/”)
if (location === ‘’) {
$w(‘#button4’).hide();
} else if (location === “shop”) {
$w(‘#button4’).hide();
} else {
$w(‘#button4’).show();
}
if (location === ‘’) {
$w(‘#shoppingCartIcon1, #loginSocialBar1’).show();
} else if (location === “shop”) {
$w(‘#shoppingCartIcon1, #loginSocialBar1’).show();
} else {
$w(‘#shoppingCartIcon1, #loginSocialBar1’).hide();
}
});
That worked great for the actual “shop” page, however, when people click on any other store pages like product pages, cart, and the thank you page, it goes back to the “Buy Now” button. I would like all of those pages (and possibly the my account/orders/addresses/wishlist/wallet pages) to also show the Login bar and shopping bag.
How do I make this header change work selectively for multiple pages?
I’ve searched everywhere and have pretty much no coding skills-- I would be incredibly grateful for some help in achieving this.
Please realize that you can’t just “copy and paste” code and expect it to work. You need to understand what’s happening if you expect to be able to write code that does what you want.
If you want to hide or show a button on a page (or pages), you will need to determine the conditions under which the button will be hidden or shown. Depending on the conditions, you might be able to include the hide/show code in the site’s masterpage.js where you could then give you site-wide control of the button.
Or, you can just check the appropriate conditions on each page and then show or hide the button appropriately. That could be tedious if you have a large number of pages.
This really depends on the structure of you site, what pages you have, and what conditions you need.
Since you as you said you have no coding skills, I wiould recommend learning about programming with Corvid. T he following articles that will help you start working with Corvid:
If you find that you are having difficulty with code and need assistance, you may want to check out the Wix Marketplace - it’s a place where you can look for Corvid experts for hire.
Hi Yisrael, thank you for the reply. I appreciate the links also.
I did end up setting all three of the elements to show in the masterpage.js, then hiding the appropriate elements with a bit of code on each individual page. You’re right about it being somewhat tedious that way. I know exactly what pages I want to have the login bar & cart icon on and I want the rest of the pages to have the buy now button (including future pages). Would that be difficult to accomplish from the masterpage.js?
If so, I will just keep adding the appropriate hide code to each new page until I learn how to write a global code that will accomplish the same thing without the need to do that.