Checkout Validation: customer have a amount limit in the month

customer have limit for purchasing in the month if customer spent amount => $10,000 so checkout will be block validation error showing in the checkout page,

this is my checkout.liquid code unfortunately checkout.liquid is deprecated up coming month so how can apply this code into checkout extensibility,

We made a solution for this by using the app called Checkout Validator. There we can set up a rule for Total Amount spend and you can also give dates (On our Roadmap). And Also give custom message. The app fully based on new checkout extensibility.

App Link : https://apps.shopify.com/checkout-validator

This is how it looks like,

@sabeeh This App showing if total spent amount > 10000 then work but my condition is different, I want to find total spent amount get value by range for example every 1st day of month to current date check if condition true or false

Thanks for the clarification.
This can be done combination with shopify flow,

  1. Store current month total spent amount in metafield. With shopify flow update this value when every order is created
  2. With checkout validator check for the metafield value and if it is greater than 10000 then block the order

I’m trying to use Shopify Flow, but it isn’t working as expected. The flow retrieves the total spent amount from the user’s first order to the last, rather than by a specific date range.

If you know how to get the spent amount by a date range in Shopify Flow, please create a flow and show me.

Thanks in advance!

You might need to run custom code to calculate in flow, Attached a similar flow that will store current day sales in shop metafield. You can refer this and update as required

803ced5d0235f9d359f373518a1514773d61001ea222f2f02a41a12b25422d8c:{“__metadata”:{“version”:0.1},“root”:{“steps”:[{“step_id”:“a32a22b6-91a0-4490-b5c5-edee01717659”,“step_position”:[940,1360],“config_field_values”:,“task_id”:“shopify::admin::order_created”,“task_version”:“0.1”,“task_type”:“TRIGGER”,“description”:null,“note”:null,“name”:null},{“step_id”:“31b2c800-4b03-11ef-a5a4-6de6866cd29a”,“step_position”:[1320,1520],“config_field_values”:[{“config_field_id”:“input”,“value”:“query{\n shop{\n name\n ianaTimezone\n metafields{\n namespace\n key\n value\n }\n }\n order {\n createdAt\n totalPriceSet{\n presentmentMoney{\n amount\n }\n }\n }\n \n}”},{“config_field_id”:“script”,“value”:“export default function main(input) {\n // Find the metafield for today’s sales\n let todaySalesMetafield = input.shop.metafields.find(\n (metafield) => metafield.namespace === "custom" && metafield.key === "sale_day_date"\n );\n\n // Get the current date in the shop’s timezone\n const orderDate = new Date(input.order.createdAt);\n const currentDate = orderDate.toISOString().split(‘T’)[0]; // Format: YYYY-MM-DD\n\n // Initialize or reset todaySales\n let todaySales = 0;\n\n // If the metafield exists and its date matches the current date, use its value\n if (todaySalesMetafield && todaySalesMetafield.value) {\n const [storedDate, storedSales] = todaySalesMetafield.value.split(‘|’);\n if (storedDate === currentDate) {\n todaySales = parseInt(storedSales) || 0;\n }\n }\n\n // Add the current order amount to todaySales\n todaySales += parseFloat(input.order.totalPriceSet.presentmentMoney.amount);\n\n // Prepare the new value to be stored in the metafield\n const today_sales_config = ${currentDate}|${todaySales};\n\n return {\n today_sales_config,\n total_sales: todaySales,\n };\n}”},{“config_field_id”:“output_schema”,“value”:“"The output of Run Code"\ntype Output {\n "The message returned by the script"\n today_sales_config: String!\n total_sales:Int!\n \n}”}],“task_id”:“shopify::flow::run_code”,“task_version”:“0.1”,“task_type”:“ACTION”,“description”:null,“note”:null,“name”:“Run code”},{“step_id”:“b5d9a720-4b03-11ef-a5a4-6de6866cd29a”,“step_position”:[1720,1500],“config_field_values”:[{“config_field_id”:“namespace”,“value”:“custom”},{“config_field_id”:“key”,“value”:“today_sales”},{“config_field_id”:“value”,“value”:“{{runCode.total_sales}}”},{“config_field_id”:“value_type”,“value”:“single_line_text_field”}],“task_id”:“shopify::admin::add_shop_metafield”,“task_version”:“0.1”,“task_type”:“ACTION”,“description”:null,“note”:null,“name”:null},{“step_id”:“6ab7bf50-4bdc-11ef-9443-d7dcbd79048d”,“step_position”:[2080,1500],“config_field_values”:[{“config_field_id”:“namespace”,“value”:“custom”},{“config_field_id”:“key”,“value”:“today_sales_config”},{“config_field_id”:“value”,“value”:“{{runCode.today_sales_config}}”},{“config_field_id”:“value_type”,“value”:“single_line_text_field”}],“task_id”:“shopify::admin::add_shop_metafield”,“task_version”:“0.1”,“task_type”:“ACTION”,“description”:null,“note”:null,“name”:null}],“links”:[{“from_step_id”:“a32a22b6-91a0-4490-b5c5-edee01717659”,“from_port_id”:“output”,“to_step_id”:“31b2c800-4b03-11ef-a5a4-6de6866cd29a”,“to_port_id”:“input”},{“from_step_id”:“31b2c800-4b03-11ef-a5a4-6de6866cd29a”,“from_port_id”:“output”,“to_step_id”:“b5d9a720-4b03-11ef-a5a4-6de6866cd29a”,“to_port_id”:“input”},{“from_step_id”:“b5d9a720-4b03-11ef-a5a4-6de6866cd29a”,“from_port_id”:“output”,“to_step_id”:“6ab7bf50-4bdc-11ef-9443-d7dcbd79048d”,“to_port_id”:“input”}],“patched_fields”:,“workflow_name”:“Sum orders”}}

Sabeeh I’m confused because You said store current day sales but we need customer sales value/spent amount

Hey Ahsan,

I have shared an example of similar logic, using write code block of flow, As mentioned It is an example You need to modify that to a user metafield version