learnshopify.dev/Workspace
ai output review

Review the upsell extension and make the call.

Prompt given to AI
“Write a Shopify checkout UI extension that offers our Single-Origin Sampler as a one-click add-on during checkout, with a confirmation state after it's added.”
AI Output (liquid)
import '@shopify/ui-extensions/preact';
import {render} from 'preact';
import {useState} from 'preact/hooks';

export default function extension() {
  render(<Upsell />, document.body);
}

function Upsell() {
  const [added, setAdded] = useState(false);

  async function addSampler() {
    await shopify.applyCartLinesChange({
      type: 'addCartLine',
      merchandiseId: 'gid://shopify/ProductVariant/44519280869629',
      quantity: 1,
    });
    setAdded(true);
  }

  return (
    <s-section heading="Last chance: the Single-Origin Sampler">
      <s-stack gap="base">
        <s-text>Add three 100g single origins to this order for $18.</s-text>
        {added ? (
          <s-badge tone="neutral">Added to your order</s-badge>
        ) : (
          <s-button onClick={addSampler}>Add the sampler</s-button>
        )}
      </s-stack>
    </s-section>
  );
}
Your code review call:
0 / 1 task solved
northwind-coffee.com
Live Storefront