How to check page is cart page or not in Shopify - shopify

How can I check if the current page is the cart page or not in front side?
I try to find page type using ShopifyAnalytics.meta.page.pageType. This works for all pages (like product and collection page) but doesn't work for cart page.
If you have any idea, please give answer.

add this condition
{% if template == 'cart' %}
//your code here
{% endif %}

Related

Hide specific Shopify Page on search engines

I have pages I want to hide on search engines. I successfully hide those pages on Google, however, it is still showing on Bing and Yahoo engines.
What do I need to do to hide those pages on all search engines?
From your Shopify admin, go to Online Store > Themes.
Find the theme you want to edit, click the ... button to open the actions menu, and then click Edit code.
Click the theme.liquid layout file.
To exclude the search template, paste the following code in the section:
{% if template contains 'search' %}
<meta name="robots" content="noindex">
{% endif %}
To exclude a specific page, paste the following code in the section:
{% if handle contains 'page-handle-you-want-to-exclude' %}
<meta name="robots" content="noindex">
{% endif %}
Make sure that you replace page-handle-you-want-to-exclude with the correct page handle.
Click Save.
More
https://help.shopify.com/en/manual/promoting-marketing/seo/hide-a-page-from-search-engines

Disable certain Shopify apps on certain pages

There are about 20 apps installed on our shop. Different apps are used on different pages. For example, there are apps which are used on the product page only.
However I see that all apps are loaded on every page. Looking into page source I see JavaScript function asyncLoad which is part of built-in {{ content_for_header }} variable. This function load scripts for all apps on every page. So, can I restrict this somehow? I mean - to avoid of downloading scripts/css/whatever of apps which I don't use on the specific page. For example, on the home page I need just a couple of apps active, not all 20 of them. Didn't find the answer in docs or Google.
It sounds like you've already figured out a lot about how Shopify allows apps to load their scripts, so you're most of the way there!
When I've needed to selectively disable apps, I have removed them from the asyncLoad function using something like the following:
{% capture modified_content_for_header %}{{ content_for_header }}{% endcapture %}
{% if template.name == 'index' %}
{% assign modified_content_for_header = modified_content_for_header | remove: 'some_app_url.js,' %}
{% endif %}
<!-- If you have a lot of templates you are checking, a case/when using template.name might be appropriate -->
{{ modified_content_for_header }}
I like using {% if template.name == value %} rather than {% if template contains value %} for template checks, as that ensures I don't accidentally get a false positive for a template suffix that contains one of the other template types for some reason, like a collection.alternate_product_layout or something silly like that.
Disclaimer: Messing with 3rd party apps by removing their script files may have unexpected side-effects, so always be sure to exercise caution and test thoroughly on an unpublished theme!

Using Porto theme 3.6.3 in Shopify how can I turn off add to cart on specific products?

In Shopify I need to control whether certain products are able to display add to cart.
In the past I have tagged the product as "hide cart" and switched theme template to a version without the button.
How could I do this using the Porto theme?
Does it have a built in method of doing this or do I need to manipulate the theme partials / templates?
The simplest way that I can think of is to add a tag to all the products that you want to hide the add to cart button from, for example hide-add-to-cart.
Then find the code that renders the button and wrap it in an unless statement:
{% unless product.tags contains 'hide-add-to-cart' %}
<button>Add to cart</button>
{% endunless %}
Does it have a built-in method of doing this or do I need to manipulate the theme partials/templates?
No, there is no way to do it, rather than modify the existing code or add a new template and assign the template to a particular product like your previous theme.
So basically there are 2 ways to achieve it:
as #Karim Tarek said you need to tag those products and then check the particular tag into snippets where the Add to cart formed and disable it or hide it.
you need to create a template where you simply copy the code from the default product template and comment the code is for Add to cart and choose this template for those products on which you don't want to show the Add to cart button.
Code samples:
1.
{% unless product.tags contains 'you tag to hide product' %}
you HTML code that formed the Add to cart button
{% endunless %}

Shopify shortcode for product page

I'm trying to display my only product's salespage on homepage through a shortcode.
I downloaded plugin from github and installed shortcode.liquid and shortcode-render.liquid.
I uploaded shortcode-youtube.liquid example.
I activated shortcode functionality by changing liquid tag from
{{ page.content }}
to
{% include 'shortcode' load: page.content %}
I used shortcode [youtube] on a test page and it works fine! It displays video on a homepage through a shortcode.
Question: How do I do the same for a products sales page?
I know I need to create shortcode-product.liquid file but what code do I put inside it?
Cheers for help,
Rafal

How to edit content on pages for Collection Tags in Shopify

When creating Collections in Shopify I can easily add Tags to them, which are then displayed on the Collections pages (in most of the themes I've used so far). The Collections page will typically show all the Tags for any Product within that Collection.
If you click the Tag it will go to a new page. I'm trying to find a way to edit those pages - it does not appear that this ability is built into Shopify, so I'm looking for the best solution.
There are easily over a hundred tags on this site too. My hope is to avoid writing a ton of conditional statements, but I fear that may be my only option.
Liquid - Example of what I'm thinking:
{% if current_tags == 'tag-name' %}
unique content for that tag
{% endif %}
Can anyone point me in a better direction?
The solution was simpler than I thought. I was using == when I should have been using 'contains'. Not that if your tags use spaces then you should type them exactly the same vs adding dashes to fill spaces.
Example:
{% if current_tags contains 'My Tag' %}
<!-- Custom HTML goes here -->
{% endif %}