Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Adding a New Single line Metafield and collapsible metafields to products

Adding a New Single line Metafield and collapsible metafields to products

ar0305
Visitor
1 0 2

ar0305_0-1728600273874.png

need to add under the shipping availability, but not to appear when no content is added?

 

Replies 2 (2)

Kyle_liu
Shopify Partner
277 38 50

Hi  @ar0305 

 

You can try this code.

{%- if product.metafields.custom.shipping_availability != blank -%}
    <p>{{product.metafields.custom.shipping_availability.value}}</p>
{% endif %}

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee

ZestardTech
Shopify Partner
5902 1066 1412

Hi @ar0305 

Step 1: Create a Metafield for Shipping Availability
Go to your Shopify Admin.
Navigate to Settings > Custom data > Metafields.
Select Products or the appropriate resource type.
Click Add definition.
Create a metafield definition for your shipping availability, such as:
Namespace: shipping
Key: availability_info
Content type: Single line text (or any other type that suits your needs)
 
Step 2: Add Content to the Metafield
Go to your Products section in the Shopify Admin.
Select a product where you want to add shipping availability information.
Scroll down to the Metafields section.
Enter the relevant shipping information in the metafield you created (availability_info).
Save the product.
 
Step 3: Modify Your Theme Code
Now, you need to modify the relevant Liquid file in your theme to display the metafield only if it has content.
 
Go to your Shopify Admin.
Navigate to Online Store > Themes.
Click on Actions > Edit code on the theme you are using.
Find the file where the shipping availability is displayed. This is usually in product-template.liquid or product-form.liquid.
Add the following code snippet where you want the shipping availability to be displayed:
 

 

{% if product.metafields.shipping.availability_info != blank %}
  <div class="shipping-availability">
    <h3>Shipping Availability</h3>
    <p>{{ product.metafields.shipping.availability_info }}</p>
  </div>
{% endif %}

 



Want to modify or develop new app, Hire us.
If helpful then please Like and Accept Solution .
Email: support@zestard.com
Shopify Apps URL :- https://apps.shopify.com/partners/zestard-technologies
Custom Modifications Into Shopify Theme | Shopify Private App | SEO & Digital Marketing