learnshopify.dev/Workspace
ai output review

Review Copilot's payment Function and make the call.

Prompt given to AI
“Write a Shopify payment customization function in JavaScript for the cart.payment-methods.transform.run target that hides the Cash on Delivery payment method when the cart total is over 200 euros.”
AI Output (liquid)
// src/cart_payment_methods_transform_run.js
//
// Input query (cart_payment_methods_transform_run.graphql):
//
//   query CartPaymentMethodsTransformRunInput {
//     cart {
//       cost {
//         subtotalAmount { amount }
//       }
//     }
//     paymentMethods { id name }
//   }

export function cartPaymentMethodsTransformRun(input) {
  const total = parseFloat(input.cart.cost.subtotalAmount.amount);
  const cod = input.paymentMethods.find(
    (method) => method.name === "Cash on Delivery (COD)"
  );

  if (total > 200) {
    return {
      operations: [{ paymentMethodHide: { paymentMethodId: cod.id } }],
    };
  }

  return { operations: [] };
}
Your code review call:
0 / 1 task solved
northwind-coffee.com
Live Storefront