在 WooCommerce 'Thank You' 页面上添加产品特定消息。
Add product specific messages on a WooCommerce 'Thank You' page.
我有几个产品在购买后需要额外的信息。如果已购买特定产品,如何显示简单消息?此外,如果订单中的产品属于特定产品类别,我想显示一条简单消息。
看看here.
如果购买了产品 X,此代码段将使您能够将用户重定向到特定页面。
如果您有不止一种产品想要自定义重定向页面,您可以在此处使用多个 if 语句。
如果购买了特定产品类别的商品,这应该会向您发送消息:
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' );
虽然未经测试,因此您的里程可能会有所不同。
我有几个产品在购买后需要额外的信息。如果已购买特定产品,如何显示简单消息?此外,如果订单中的产品属于特定产品类别,我想显示一条简单消息。
看看here.
如果购买了产品 X,此代码段将使您能够将用户重定向到特定页面。
如果您有不止一种产品想要自定义重定向页面,您可以在此处使用多个 if 语句。
如果购买了特定产品类别的商品,这应该会向您发送消息:
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' );
虽然未经测试,因此您的里程可能会有所不同。