WooCommerce订阅: WooCommerce订阅的所有产品
有没有人知道是否有办法禁用特定产品变体的订阅选项?
即具有2x属性的产品: attr-1,attr-2
所有这些都可以单独购买,也可以通过PDP上的子程序购买,是否有一种方法可以禁用其中一个属性的订阅选项?
在没有大量JS逻辑的情况下,没有使用wcsatt_product_subscription_scheme过滤器的简洁方法。
已经向WC伸出援手,如果有一个更优雅的解决方案的话,我很乐意回报
发布于 2022-05-12 11:06:18
add_filter('woocommerce_subscription_variation_is_purchasable', 'conditional_variation_subscription_is_purchasable', 20, 2);
function conditional_variation_subscription_is_purchasable($purchasable, $product) {
$check_attributes = [
'attribute_pa_color' => 'black',
'attribute_pa_slow-connect' => 'very-slow',
];
$matching_variation = find_matching_product_variation_id($product->get_parent_id(), $check_attributes);
if ($matching_variation == $product->get_id()) {
$purchasable = false;
}
return $purchasable;
}
function find_matching_product_variation_id($product_id, $attributes) {
return (new \WC_Product_Data_Store_CPT())->find_matching_product_variation(
new \WC_Product($product_id),
$attributes
);
}将代码添加到活动主题functions.php文件中。根据需要更改属性名称和值。
https://stackoverflow.com/questions/72211872
复制相似问题