我正在使用WooCommerce捆绑产品插件,我正在尝试默认选中我的捆绑产品之一。
到目前为止,我已经设法找到一种方法来检查它们。基本上我想要这个过滤器来检查产品类型是否是订阅,然后添加以下过滤器。
有人可以帮我这个吗?
add_filter( 'woocommerce_bundled_item_is_optional_checked', 'wc_pb_is_optional_item_checked', 10, 2 );
function wc_pb_is_optional_item_checked( $checked, $bundled_item ) {
return true;
}
答案 0 :(得分:0)
你应该试试这个(我不确定100%,因为我不使用Bundled Products插件):
add_filter( 'woocommerce_bundled_item_is_optional_checked', 'wc_pb_is_optional_item_checked', 10, 2 );
function wc_pb_is_optional_item_checked( $checked, $bundled_item ) {
// If an item of the bundled product is a subscription
if(wc_get_product($bundled_item->item_id)->is_type('subscription'))
$checked = true;
return $checked;
}
这应该有用。