Real-Time Shopify Offer Block Development

Job ID: 39958378

Budget: $30 – $250 USD

Dynamic Offer Block with Real-Time Availability Check
Platform: Shopify (Online Store 2.0 Theme) Required Skills: Liquid, HTML, CSS, Vanilla JavaScript (or modern framework knowledge), Shopify AJAX API.
Scenario
We need to create a special, highly visible block intended to encourage the buyer to add a product to their cart. This block must be displayed on all product pages, but its content should dynamically react to the inventory level and the current cart contents.
Programming Requirements
1. Liquid Offer Block Creation
Create a new Liquid snippet (filename: offer-block.liquid) that needs to be inserted into the main-product.liquid section file above the "Add to Cart" button.
Liquid Logic: The block must display one of three distinct messages, based on the currently selected product variant (using product.selected_or_first_available_variant):
A) If inventory is low (<= 5 units):
Message: "Only {{ variant.inventory_quantity }} left in stock! Grab yours before it's gone!"
B) If the item is already in the cart:
Message: "This item is already in your cart! Proceed to checkout."
C) Standard Message (inventory > 5 units and not in cart):
Message: " Add to cart now and qualify for expedited shipping!"
2. Dynamic Updates (JavaScript / AJAX)
You must ensure this block updates its information in real-time without a page refresh, responding to two key events:
A) Variant Change: When the buyer selects a different product variant (e.g., Size S to M), the block must check the new variant's inventory and update the message (switching between A, B, or C).
B) Successful Cart Addition: When the item is successfully added to the cart (even if the buyer stays on the product page), the block must automatically switch to Message B (as the item is now in the cart). This requires handling the successful response from the /cart/add.js AJAX request.
Visual Requirements (CSS)
Use distinct colors (CSS) to reflect the urgency/status of the messages:
A (Low Stock): Yellow / Orange background color.
B (In Cart): Bright Green background color.
C (Standard): Blue or a neutral background color.
Submission Requirements
Provide the complete offer-block.liquid code.
all JavaScript code responsible for the dynamic updates and AJAX handling.
Explain clearly where and how this code was integrated into the main theme files.
Related categories: JavaScript AJAX CSS HTML Shopify Web Development