1 回答
TA贡献1785条经验 获得超4个赞
利用:$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,
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报