Shopify结账动态生成html类?

发布于 2025-01-15 10:24:37 字数 421 浏览 1 评论 0原文

我即将到达结帐处以获取最终支付价格:

  let checkout = await fetch("/checkout/");
   checkout = await checkout.text();
   let total_price = checkout.match(
            /<dl class="order-summary-toggle(.*?)<\/dl>/gim
          );

问题是我注意到在某些商店结帐页面上有动态生成的类,但我不知道为什么并且无法重现?

屏幕

有人知道为什么会发生吗?或者是否有更好的方法来获取结账最终价格?

I'm reaching the checkout for getting the final price to pay :

  let checkout = await fetch("/checkout/");
   checkout = await checkout.text();
   let total_price = checkout.match(
            /<dl class="order-summary-toggle(.*?)<\/dl>/gim
          );

The problem is i noticed on some store checkout page got dynamic generated class, and i dont know why and cant reproduce?

screen

Is someone know why is it happening ? or if there is an better way to get the checkout final price ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

用心笑 2025-01-22 10:24:37

html 不会完整,因为是使用 Javascript 动态创建的。

如果您使用的是液体,则可以使用 {{cart.total_price}} 访问总价。

如果没有,并且您想使用 cartjs api 您可以调用 /cart.js 并使用字段“total_price”

$.ajax({
    type: 'GET',
    url: '/cart.js',
    dataType: 'json',
    success: function (data) {
        alert("Your total is: "+data.total_price);
    },
    error: function () {
    }
});

The html will not be complete because is dynimically created with Javascript.

If you are using liquid the total price can be accessed with {{cart.total_price}}.

If not, and you want to use the cartjs api you can call /cart.js and use the field "total_price"

$.ajax({
    type: 'GET',
    url: '/cart.js',
    dataType: 'json',
    success: function (data) {
        alert("Your total is: "+data.total_price);
    },
    error: function () {
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文