【问题标题】:cart and checkout doesn't work in woocommerce购物车和结帐在 woocommerce 中不起作用
【发布时间】:2019-12-21 22:18:28
【问题描述】:

我将 woocommerce/template 包含在我的主题中,名称为:'woocommerce',并在我的 functions.php 中使用 add_theme_support() 来介绍它。 但是当用户将产品添加到购物车并想要查看购物车时,用户重定向到 index.php 我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    @Ali 请分享你的代码,让我有更好的想法。

    1. 将主题支持代码添加到functions.php文件

      函数 mytheme_add_woocommerce_support() { add_theme_support('woocommerce'); } add_action('after_setup_theme', 'mytheme_add_woocommerce_support');

    2. 在您的主题文件夹中创建文件夹“woocommerce”。

    3. 将“wp-content/plugins/woocommerce/templates/”中的所有文件复制到此文件夹。
    4. 将以下代码添加到functions.php文件中。

      函数 my_custom_add_to_cart_redirect( $url ) { $url = get_permalink(get_option('woocommerce_checkout_page_id')); 返回 $url; } add_filter('woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect');

    试试这个。

    【讨论】:

    • 谢谢你的回答,正是我做了这个步骤,但仍然有问题.......没有太多代码我刚开始学习woocommerce,它只是index.php, style.css , functions.php 和 woocommerce 目录
    • @AliNorouzi 试试这个代码,如果你需要任何其他帮助,请告诉我。谢谢。
    • 这是我的functions.php ---- function mytheme_add_woocommerce_support() { add_theme_support('woocommerce'); } add_action('after_setup_theme', 'mytheme_add_woocommerce_support');
    • 我收到此错误 ::: 注意:WC_Cart::get_cart_url 自 2.5 版起已弃用!请改用 wc_get_cart_url。在 C:\xampp\htdocs\wp\wp-includes\functions.php 第 4435 行
    • @AliNorouzi 你也可以做管理员,转到 WooCommerce > 设置 > 产品 > 显示并启用选项:“成功添加后重定向到购物车页面”
    【解决方案2】:

    我终于修好了。太愚蠢了。 我只是忘记在我的主题中添加 page.php

    <?php get_header(); if (have_posts()) {while (have_posts({the_content();}}get_footer();
    

    因为购物车快捷方式需要显示在页面中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-17
      • 2013-02-25
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多