【发布时间】:2017-04-08 18:45:42
【问题描述】:
我正在创建一个电子商务网站。我可以在我的主题的 functions.php 文件中添加什么,以允许客户仅从商店购买一种产品,然后在 1 周内禁用任何其他购买?
客户可以购买任何产品,但购买后一周内不能再购买任何类型的产品。客户只能在一周后进行任何其他购买。
我只能禁用使用此代码对产品进行的购买:
add_filter( 'woocommerce_add_cart_item_data', 'woo_allow_one_item_only' );
function woo_allow_one_item_only( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return $cart_item_data;
}
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed' ),
) );
// Order count
$order_count = 1;
if ( count( $customer_orders ) >= $order_count ) {
add_filter( 'woocommerce_is_purchasable', false );
}
【问题讨论】:
标签: php wordpress woocommerce product orders