我的问题正是这样: -根据产品属性和付款方式在“谢谢”页面上打印文本
我有一段完美的代码:
{
"Question Communicating": "Natural language",
"interpretation_type": "recognition",
"output": [
"test",
"test2",
"something"
],
"Question Learning": "Reinforcement"
}
现在,我只想在显示产品选择条件和付款方式(例如bacs)时返回另一条文本。
示例A:
因此,仅在这种情况下,才会显示“谢谢”页面上的文本:
或
示例B:
因此,仅在这种情况下,才会显示“谢谢”页面上的文本:
谢谢!
答案 0 :(得分:2)
使用:$order->get_payment_method();
function action_woocommerce_thankyou( $order_id ) {
// Get $order object
$order = wc_get_order( $order_id );
// Get items
$items = $order->get_items();
// Set variable
$found = false;
// Set variable
$output = '';
// Loop
foreach ( $items as $item ) {
// Add whatever variation id you want below here.
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 9647 ) {
$output = 'Thank you for buy VARIABLE A-9647';
$found = true;
break;
}
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 9648 ) {
$output = 'Thank you for buy VARIABLE B-9648';
$found = true;
break;
}
}
// Get payment method
$payment_method = $order->get_payment_method();
// Payment method = basc & found = true
if ( $payment_method == 'bacs' && $found ) {
$output .= ' YOUR PAYMENT IS BACS';
}
// Print result
echo $output;
}
add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );
编辑
在页面顶部的订单详细信息之前显示文字
function change_order_received_text( $str, $order ) {
// Get items
$items = $order->get_items();
// Set variable
$found = false;
// Loop
foreach ( $items as $item ) {
// Add whatever variation id you want below here.
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 9647 ) {
$str = 'Thank you for buy VARIABLE A-9647';
$found = true;
break;
}
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 9648 ) {
$str = 'Thank you for buy VARIABLE B-9648';
$found = true;
break;
}
}
// Get payment method
$payment_method = $order->get_payment_method();
// Payment method = basc & found = true
if ( $payment_method == 'bacs' && $found ) {
$str .= ' YOUR PAYMENT IS BACS';
}
return $str;
}
add_filter('woocommerce_thankyou_order_received_text', 'change_order_received_text', 10, 2 );