[英]Replace Upsells with products from a specific product category in Woocommerce 3
我遇到以下情况-到目前为止,我始终会按1设置Upsell产品自定义设置,因为无法在管理员中选择产品类别。
现在,在对不再使用的产品进行大范围清洗之后,站点上的许多产品页面上都有1、2或3,而不是默认数量的4个Upsell产品,这破坏了设计。
有没有一种方法可以用特定产品类别的产品代替那些加价销售?
任何帮助表示赞赏。
要用来自特定产品类别的产品替换woocommerce加售,请使用以下代码(您将在其中定义您的产品类别块) :
add_filter( 'woocommerce_product_get_upsell_ids', 'custom_upsell_ids', 20, 2 );
function custom_upsell_ids( $upsell_ids, $product ){
// HERE define your product categories slugs in the array
$product_categories = array( 't-shirts' ); // <===== <===== <===== <===== <=====
// Return the custom query
return wc_get_products( array(
'status' => 'publish', // published products
'limit' => 4, // 4 products
'category' => $product_categories, // Product categories
'orderby' => 'rand', // Random order
'exclude' => array( $product->get_id() ), // Exclude current product
'return' => 'ids', // Query returns only IDs
) );
}
代码进入活动子主题(或活动主题)的function.php文件中。 经过测试和工作。
查询设置为按随机顺序显示特定产品类别中的4个产品(当前产品除外)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.