What's your biggest current challenge? Have your say in Community Polls along the right column.

Display Cart Note on Checkout and Thank You Page

Display Cart Note on Checkout and Thank You Page

DzignM
Shopify Partner
1 0 1

Hi, 

 

I'm writing my first app extension (and I am a relative newbie to it all) where I am trying to display the cart note (ideally I will be adding in two, as we need the customer to in put 2 codes from their existing product) on the checkout and thank you page below the relevant product. 

 

I got the position to work with a simple text string but now I am trying to target the attribute I am coming a bit stuck. 

Any ideas, thoughts welcomed.

import {
  reactExtension,
  Text,
  useApi,
  useCartLineTarget,
} from "@shopify/ui-extensions-react/checkout";
import { useEffect, useState } from "react";

// 1. Choose an extension target
const thankYouBlock = reactExtension(
  "purchase.thank-you.cart-line-item.render-after",
  () => <Extension />
);

export { thankYouBlock };

const orderStatusBlock = reactExtension(
  "customer-account.order-status.cart-line-item.render-after",
  () => <Extension />
);

export { orderStatusBlock };

const checkoutBlock = reactExtension(
  "purchase.checkout.cart-line-item.render-after",
  () => <Extension />
);

export { checkoutBlock };

function Extension() {
  const { query } = useApi();
  const [cartAttribute, setCartAttribute] = useState<string | null>(null);

  useEffect(() => {
    async function fetchCartAttribute() {
      const result = await query<{
        cart: {
          attributes: Array<{ key: string; value: string }>;
        };
      }>(`{
        cart {
          attributes {
            key
            value
          }
        }
      }`);

      if (!result.errors) {
        const attribute = result.data.cart.attributes.find(
          (attr) => attr.key === "CartNote" // Replace with relevant attribute key
        );
        setCartAttribute(attribute ? attribute.value : null);
      } else {
        console.error(result.errors);
      }
    }

    fetchCartAttribute();
  }, []);

  if (!cartAttribute) return null;

  return (
    <Text emphasis="bold" size="small">
      {cartAttribute}
    </Text>
  );
}



Reply 1 (1)

KetanKumar
Shopify Partner
37433 3664 12119

@DzignM  oh sorry for that issue checkout page customization allow  only Shopify plus plan and sorry thank you not allow any customization

If helpful then please Like and Accept Solution. Partnership of your ️ Coffee Tips and my code can bring miracles.
Want to modify or custom changes on store Hire Me.
- Feel free to contact me on bamaniyaketan.sky@gmail.com regarding any help Shopify Partner | Skype : bamaniya.sky
PSD to Shopify | Shopify Design Changes | Shopify Custom Theme Development and Desing | Custom Modifications In to Shopify Theme | SEO & Digital Marketing