向Woocommerce 3中的“谢谢”页面添加一条附加消息

时间:2018-07-27 12:26:46

标签: php wordpress woocommerce checkout hook-woocommerce

Example “谢谢。已收到您的订单。”后需要添加自定义消息。 变量已添加到我的消息中。它包含订单总额的百分比。

以下代码有效,但我不确定:

#!/bin/sh
BASE_DIR=/opt/java/hotspot/8/64_bit/

version=$(ls $BASE_DIR | grep -Eo "([0-9]+\.?){3}(_[0-9]+)?" | sort -Vr | head -1)

if [ -n "$version" ]; then
  folder=$(find $BASE_DIR -maxdepth 1 -name "*${version}*")
  echo "Setting JAVA_HOME to $folder."
  JAVA_HOME="$folder"
  export JAVA_HOME
else
  echo 1>&2 "No JDK installation found in ${BASE_DIR}!"
  exit 1
fi

这是更好的方法吗?如何增强我的代码?

2 个答案:

答案 0 :(得分:1)

您的代码是正确的,但是您可以使用sprintf()和可翻译的文本来使其更好一点:

add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $thankyou_text, $order ) {
    $order_saving = (float)( get_option( 'wc-custom-percent' ) * $order->get_total() / 100 ); // Bonus amount
    $bonus_link   = '#';

    return sprintf( __("%s You participate in the bonus program, your bonus interest from this order is %s. %s", "woocommerce"),
    $thankyou_text,
    wc_price($order_saving),
    '<a href="'.$bonus_link.'">' . __("Learn more about the bonus program.", "woocommerce") . '</a>' );
}

代码进入活动子主题(或活动主题)的function.php文件中。经过测试并可以正常工作。

enter image description here

答案 1 :(得分:0)

add_action( 'woocommerce_thankyou', 'my_custom_thankyou_page', 20 );
function my_custom_thankyou_page( $order_id ){  
    $order = wc_get_order($order_id);
    $order_total = $order->get_total();
    $percent = get_option( 'wc-custom-percent' ); // Percentage
    $order_saving = (float)($percent * $order_total / 100); // Bonus amount

    $new_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;

}