在WooCommerce的“谢谢”页面上添加产品特定消息。

问题描述:

我有一些产品在购买后需要额外的信息。如果购买特定产品,我如何显示简单信息?此外,如果订单中的产品属于特定产品类别,我想显示一条简单消息。在WooCommerce的“谢谢”页面上添加产品特定消息。

如果从特定产品类别的项目购买这应该让你一个消息:

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

看一看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