I am testing locking pricing for non-members with code from this post: https://theprompted.co/blogs/tutorials/locked-content-free-tutorial
Everything has gone well so far, but I am having an issue with the Shopify Product Grid alignment when I actually apply the settings. Product Grid aligns fine in several columns with my products,
but when I click “lock all product pricing” the product grid is forced into 1 column instead of 4 and squishes the products.
Do you have any idea why this happens or how to fix it? I am looking for a solution that would allow me to use this for my site. I’ve posted before and after screenshots.
2 Likes
Hi @mrsclgamble , can you share your store url?
@mrsclgamble , can you enable the lock all product price option?
Not publicly. I have done all of the code changes on a Theme Copy that isn’t public so that I don’t mess up my main site. This is all in the testing phase. Is there a way to share my test site with you?
@mrsclgamble , Yes, you can share it via the preview link at the bottom of the page:
@mrsclgamble , can you share price.liquid file code here , and where did you put the code there?
Here is the price.liquid code I used:
{% assign lock_pages_metaobject = shop.metaobjects.lock_pages[settings.lock_pages_metaobject] %}
{% assign locked_product_ids = lock_pages_metaobject.products_to_lock.value | map: 'id' %}
{% if customer == nil and settings.enable_locked_content and settings.lock_all_product_prices %}
<b>{{ settings.price_locked_text }}</b>
{% elsif customer == nil and settings.enable_locked_content and locked_product_ids contains product.id %}
<b>{{ settings.price_locked_text }}</b>
{% else %}
It was placed at the top of the price.liquid code:
followed by a
{% endif %}
at the end of all of the original code:
@mrsclgamble , There is an error here as you can see :
Can you paste the code here?
{% comment %}
Renders a list of product’s price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing. Default false.
- discount_badge: {Boolean} Renders a discount badge. Default false.
- price_class: {String} Adds a price class to the price element (optional)
Usage:
{% render ‘price’, product: product %}
{% endcomment %}
{% assign lock_pages_metaobject = shop.metaobjects.lock_pages[settings.lock_pages_metaobject] %}
{% assign locked_product_ids = lock_pages_metaobject.products_to_lock.value | map: ‘id’ %}
{% if customer == nil and settings.enable_locked_content and settings.lock_all_product_prices %}
{{ settings.price_locked_text }}
{% elsif customer == nil and settings.enable_locked_content and locked_product_ids contains product.id %}
{{ settings.price_locked_text }}
{% else %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_price = price | money
if settings.currency_code_enabled
assign money_price = price | money_with_currency
endif
if target == product and product.price_varies
assign money_price = ‘products.product.price.from_price_html’ | t: price: money_price
endif
assign is_pre_order = false
if product.template_suffix == ‘pre-order’
assign is_pre_order = true
endif
-%}
{% if is_pre_order %}
{{ 'products.product.pre_order' | t }}
{% endif %}
{{ ‘products.product.price.regular_price’ | t }}
{{ money_price }}
{% if settings.price_tax_suffix and cart.taxes_included %}
{{ settings.price_tax_suffix }}
{% endif %}
{% if compare_at_price > price %}
{% unless product.price_varies == false and product.compare_at_price_varies %}
{{ 'products.product.price.regular_price' | t }}
{% if discount_badge == true and target.compare_at_price > target.price and settings.sale_badge_mode != ‘none’ %}
{% render ‘badge-sale’, product: product, use_variant: use_variant %}
{% endif %}
{% if settings.currency_code_enabled %}
{{ compare_at_price | money_with_currency }}
{% else %}
{{ compare_at_price | money }}
{% endif %}
{% endunless %}
{{ ‘products.product.price.sale_price’ | t }}
{{ money_price }}
{% if settings.price_tax_suffix and cart.taxes_included %}
{{ settings.price_tax_suffix }}
{% endif %}
{% endif %}
{% unless product.selected_or_first_available_variant.unit_price_measurement == nil %}
{{ 'products.product.price.unit_price' | t }}
{{ product.selected_or_first_available_variant.unit_price | money }}
/
{{ 'accessibility.unit_price_separator' | t }}
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
{% endunless %}
{% endif %}
@mrsclgamble , Use this code instead :
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing. Default false.
- discount_badge: {Boolean} Renders a discount badge. Default false.
- price_class: {String} Adds a price class to the price element (optional)
Usage:
{% render 'price', product: product %}
{% endcomment %}
{% assign lock_pages_metaobject = shop.metaobjects.lock_pages[settings.lock_pages_metaobject] %}
{% assign locked_product_ids = lock_pages_metaobject.products_to_lock.value | map: 'id' %}
{% if customer == nil and settings.enable_locked_content and settings.lock_all_product_prices %}
**{{ settings.price_locked_text }}**
{% elsif customer == nil and settings.enable_locked_content and locked_product_ids contains product.id %}
**{{ settings.price_locked_text }}**
{% else %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_price = price | money
if settings.currency_code_enabled
assign money_price = price | money_with_currency
endif
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
assign is_pre_order = false
if product.template_suffix == 'pre-order'
assign is_pre_order = true
endif
-%}
{% if is_pre_order %}
{{ 'products.product.pre_order' | t }}
{% endif %}
{{ 'products.product.price.regular_price' | t }}
{{ money_price }}
{% if settings.price_tax_suffix and cart.taxes_included %}
{{ settings.price_tax_suffix }}
{% endif %}
{% if compare_at_price > price %}
{% unless product.price_varies == false and product.compare_at_price_varies %}
{{ 'products.product.price.regular_price' | t }}
{% if discount_badge == true and target.compare_at_price > target.price and settings.sale_badge_mode != 'none' %}
{% render 'badge-sale', product: product, use_variant: use_variant %}
{% endif %}
<s>
{% if settings.currency_code_enabled %}
{{ compare_at_price | money_with_currency }}
{% else %}
{{ compare_at_price | money }}
{% endif %}
</s>
{% endunless %}
{{ 'products.product.price.sale_price' | t }}
{{ money_price }}
{% if settings.price_tax_suffix and cart.taxes_included %}
{{ settings.price_tax_suffix }}
{% endif %}
{% endif %}
{% unless product.selected_or_first_available_variant.unit_price_measurement == nil %}
{{ 'products.product.price.unit_price' | t }}
{{ product.selected_or_first_available_variant.unit_price | money }}
/
{{ 'accessibility.unit_price_separator' | t }}
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
{% endunless %}
{% endif %}
That worked great! Thanks for the help!
1 Like