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

时间:2015-02-05 16:11:26

标签: wordpress woocommerce

我有一些产品一旦购买就需要额外的信息。如果购买了特定产品,如何显示简单信息?此外,如果订单中的产品属于特定产品类别,我希望显示简单消息。

2 个答案:

答案 0 :(得分:0)

看看here

如果购买了产品X,此代码段将使您能够将用户重定向到特定页面。

如果您有多个产品,那么您可以在此处拥有多个if语句,并希望拥有自定义重定向页面。

答案 1 :(得分: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' ); 

虽然未经测试,但您的里程可能会有所不同。

相关问题