【问题标题】:WooCommerce Wordpress can't find total order after checkout/pyamentWooCommerce Wordpress 在结帐/付款后找不到总订单
【发布时间】:2016-01-05 14:52:07
【问题描述】:

我使用自定义付款,我将其显示在 iframe 中并将变量传递到表单中。

结帐/付款后,我需要通过不带货币符号的总订单。

我找到了一种在结帐/付款之前通过购物车总数的方法

echo WC()->cart->total

在付款后结账页面 (thankyou.php) 我找到了

echo $order->get_formatted_order_total();

这将仅在thankyou.php 页面上显示带有货币符号的总订单,并且无论我尝试什么都不会传递到任何其他页面(这并不重要,因为我可以使用 etherthankyou.php 页面或实际结帐页面)

列表中的完整代码如下所示

            <?php _e( 'Total:', 'woocommerce' ); ?>
            <strong><?php echo $order->get_formatted_order_total(); ?>

我尝试过测试以查看 wordpress 如何在thankyou.php 页面和单独的页面上存储订单总额,以查看是否可以在结帐/付款后从数组中调用订单总额,但我得到的值为 0.00或者我的分页符

到目前为止我尝试过的代码:

echo $order->get_order_total();

这会破坏页面

echo WC()->$order->get_order_total();

这会破坏页面

echo $order->get_total();

这也打破了页面

结帐/付款后调用总购物车echo WC()-&gt;cart-&gt;total 将显示 0(这是有道理的)

【问题讨论】:

  • 当你说echo $order-&gt;get_total(); 分页时,显示什么错误?如果没有错误,请务必编辑您的wp-config 文件并将WP_DEBUG 转为TRUE

标签: php wordpress iframe woocommerce checkout


【解决方案1】:

如果是感谢页面,那么它就足够简单了——你只需要使用它,它应该可以在不破坏页面的情况下工作。

在您的 templates/checkout/thankyou.php 文件中,添加以下代码:

if ( ! $order) {
    echo 'No order object!';
} else if ($order->has_status( 'failed' ) {
    echo 'Order failed for some reason.';
} else {
    echo $order->get_total();
}

如果您没有$order 对象,您可以从订单id 中获取:

$order = wc_get_order( $order_id );
$order->get_total();

如果您没有可用的订单 ID 或 $order 对象,那么我们需要更多信息才能提供帮助。

【讨论】:

  • 非常感谢您找到了类似的解决方案并返回此处发布以获取文档和信息共享。
猜你喜欢
  • 1970-01-01
  • 2013-12-06
  • 2017-03-17
  • 1970-01-01
  • 2017-04-08
  • 2020-03-15
  • 1970-01-01
  • 1970-01-01
  • 2016-07-10
相关资源
最近更新 更多