【发布时间】:2020-11-29 14:00:29
【问题描述】:
在 WooCommerce 中,如果客户购买了产品(A 或 B),一个月内希望禁用从定义的产品(B、C 和 D)购买,因此产品 B、C 和 D 应该仅为该特定用户禁用一个月。
注意:在下面的代码中,我使用了来自 Check if a user has purchased specific products in WooCommerce 答案的自定义函数 has_bought_items()。
我的代码尝试:
$product_ids = array( 255, 256 );
$args2 = array(
'customer_id' => get_current_user_id()
);
$orders = wc_get_orders( $args2 );
$orders = has_bought_items( get_current_user_id(), $product_ids );
if($orders){
add_filter('woocommerce_is_purchasable', 'disable_product', 10, 2 );
function disable_product( $is_purchasable, $product ) {
if( in_array( $product->get_id(), array( 256, 257, 258 ) ) ) {
return false;
}
return $is_purchasable;
}
}
So far I am able to disable the products for the user. But I don't how can I get date from the purchase and add a month to it. Any help will be great.
【问题讨论】:
标签: php sql wordpress date woocommerce