【发布时间】:2019-01-04 13:52:23
【问题描述】:
需要在“谢谢。您的订单已收到。”之后添加自定义消息。 我的消息中添加了一个变量。它包含订单总额的百分比。
以下代码有效,但我不确定:
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
// Get order total
$order_total = $order->get_total();
$percent = get_option( 'wc-custom-percent' ); // Percentage
$order_saving = (float)($percent * $order_total / 100); // Bonus amount
$new_str = $str . ' You participate in the bonus program, your bonus interest from this order is' . $order_saving . ' euros. <a href="#">Learn more about the bonus program.</a>';
return $new_str;
}
这是更好的方法吗?如何增强我的代码?
【问题讨论】:
标签: php wordpress woocommerce checkout hook-woocommerce