wordpress - 在自定义感谢页面上显示 Woocommerce 订单详细信息
问题描述
嗨,我为我的 COD(货到付款)付款选项创建了自定义感谢页面。重定向下面的代码工作。
add_action( 'template_redirect', 'thankyou_custom_payment_redirect');
function thankyou_custom_payment_redirect(){
if ( is_wc_endpoint_url( 'order-received' ) ) {
global $wp;
// Get the order ID
$order_id = intval( str_replace( 'checkout/order-received/', '', $wp->request ) );
// Get an instance of the WC_Order object
$order = wc_get_order( $order_id );
// Set HERE your Payment Gateway ID
if( $order->get_payment_method() == 'cod' ){
// Set HERE your custom URL path
wp_redirect( home_url( '/custom-page/' ) );
exit(); // always exit
}
}
}
/custom-page/
我想显示与 Woocommerce 中相同的详细信息order-details.php
。我为我的感谢页面创建了custom-page.php
with( ),从原始 Woocommerce 复制了代码,但只加载了空白页面。有人可以帮我正确地做到这一点。谢谢/* Template Name: COD Thank you page */
order-details.php
解决方案
确保您的新 order-details.php 有一个 URL,并且该 URL 已添加到 WooCommerce > 设置 > 高级 > 已收到订单中。在那里,您将添加新订单详细信息页面的该 URL 的 slug。还有更简单的方法可以使用插件创建自定义感谢页面,例如:https ://wordpress.org/plugins/yith-custom-thank-you-page-for-woocommerce/
推荐阅读
- r - 使用 R 通过图标可视化数量
- jenkins - 如何在cps脚本jenkins中获取变量?
- qemu - RISC-V:切换到管理员模式时出现非法指令异常
- python - BeautifulSoup 限制为两位小数,以 0.00 开头的整数结果为“0.0”
- opencl - 奇怪的 OpenCL 行为
- reactjs - 从 firestore 读取数据未定义
- reactjs - react-boilerplate 代码库的生产部署抛出错误并显示空白页
- python - 检查已运行进程的状态
- python - 将函数应用于熊猫中的每一行,条件是:系列的真值不明确
- vim - 如何在 vim 编辑器中替换?