【发布时间】:2019-12-21 22:18:28
【问题描述】:
我将 woocommerce/template 包含在我的主题中,名称为:'woocommerce',并在我的 functions.php 中使用 add_theme_support() 来介绍它。 但是当用户将产品添加到购物车并想要查看购物车时,用户重定向到 index.php 我应该怎么做才能解决这个问题?
【问题讨论】:
标签: wordpress
我将 woocommerce/template 包含在我的主题中,名称为:'woocommerce',并在我的 functions.php 中使用 add_theme_support() 来介绍它。 但是当用户将产品添加到购物车并想要查看购物车时,用户重定向到 index.php 我应该怎么做才能解决这个问题?
【问题讨论】:
标签: wordpress
@Ali 请分享你的代码,让我有更好的想法。
或
将主题支持代码添加到functions.php文件
函数 mytheme_add_woocommerce_support() { add_theme_support('woocommerce'); } add_action('after_setup_theme', 'mytheme_add_woocommerce_support');
在您的主题文件夹中创建文件夹“woocommerce”。
将以下代码添加到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');
试试这个。
【讨论】:
我终于修好了。太愚蠢了。 我只是忘记在我的主题中添加 page.php
<?php get_header(); if (have_posts()) {while (have_posts({the_content();}}get_footer();
因为购物车快捷方式需要显示在页面中。
【讨论】: