我想要类似这样的字段,即称为活动的字段:是/否,如果活动=是,则表示该产品是可购买的,添加到购物车按钮将是可见的,否则“添加到购物车”按钮将不可见。
对于woocommerce中的每个产品,我都添加了一个称为active的product_meta字段,并将其存储起来,该部分的工作很酷。
现在基于该字段,我做出is_purchasable决定。
add_filter('woocommerce_is_purchasable', 'pfs_is_purchasable', 10, 2);
function pfs_is_purchasable( $is_purchasable, $object ) {
global $post;
$active_status = get_post_meta($post->ID, '_product_is_active', true );
error_log('active_status :' . $active_status );
if($active_status == 'YES'){
return true;
}
else{
return false;
}
}
现在问题是添加此过滤器后,我得到“对不起,无法购买此产品。” 请告诉我我做错了什么,或者我有什么要做的。