首页 > 解决方案 > 将 cart.php 和 cart-totals.php 移至结帐页面

问题描述

为了减少我网站上的重定向数量,我在结帐页面上添加了购物车页面。并使用此代码来做到这一点:

function cart_on_checkout_page_only() {
    if ( is_wc_endpoint_url( 'order-received' ) ) return;
    
    // add woocomerce cart shortcode on checkout page
    echo do_shortcode('[woocommerce_cart]');
}

// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );

问题出在布局上,在设备上它离订单项目太远,因为订单总额位于页面底部靠近结帐按钮的位置。我收到了很多投诉,因为人们懒得向下滚动以查看页面底部购物车中的优惠券应用程序

所以我做了以下修改:

我复制了 woocommerce 插件文件woocommerce/template/cart/cat.php and cart-totals.php

并将其粘贴到我的主题中themes/mytheme/template/cart/custom-cart.php

并在上面的代码中对其进行了修改:

function cart_on_checkout_page_only() {
    if ( is_wc_endpoint_url( 'order-received' ) ) return;

    // add custom cart template on checkout page
    get_template_part('template/cart/custom-cart');
}

// Cart and Checkout same page
add_action( 'woocommerce_before_checkout_form', 'cart_on_checkout_page_only', 5 );

我的代码完成了这项工作,但我相信应该有一种更简单、更优雅的方式来进行这种改变。有可能变得更简单吗?

顺便说一句,我使用的是儿童店面主题。

标签: phpwoocommerce

解决方案


推荐阅读