2015-02-05 115 views

回答

0

如果從特定產品類別的項目購買這應該讓你一個消息:

function so_28348735_category_based_thank_you_message ($order_id){ 
    $order = wc_get_order($order_id); 
    $show = false; 

    foreach($order->get_items() as $item) { 
     // check if a product is in specific category 
     if (has_term('your_product_category', 'product_cat', $item['product_id'])) { 
      $show = true; 
      continue; 
     } 
    } 

    if($show){ 
     echo 'your custom message'; 
    } 
} 
add_action('woocommerce_thankyou', 'so_28348735_category_based_thank_you_message'); 

未經檢驗的,所以你的里程可能會有所不同。

+0

工作很好,謝謝! – 2015-02-17 16:26:14

+0

@CraigFowler如果它工作,請選擇它作爲「答案」。 – helgatheviking 2015-02-17 22:08:35

0

看一看here

如果購買了產品X,此代碼段將使您可以將用戶重定向到特定頁面。

如果您有多個產品想要自定義重定向頁面,您可以在這裏有多個if語句。

+0

是的,我認爲這會奏效。謝謝。我只需要弄清楚如何將它從頁面底部移動到頂部。 – 2015-02-05 16:28:02

+0

@CraigFowler對不起 - 你是什麼意思的「從底部移動到頂部」? - 如果你能解釋,我可能會提供建議。 :) – Tim 2015-02-05 16:31:04

+0

- 道歉不清楚。該代碼段(以及發佈的摘錄helgatheviking)將條件消息放置在頁面底部的帳單地址下方。那有意義嗎? – 2015-02-17 16:28:56

相關問題