我可以添加到我的主题的functions.php文件中,以便用户只能购买一次产品?如果之前他们曾经在商店购买任何产品,他们就无法再次购买.
我想代码看起来像这样(伪代码),并将使用woocommerce_add_cart_item_data过滤器.
add_filter( 'woocommerce_add_cart_item_data', 'woo_check_not_bought_before' );
function woo_check_not_bought_before( $cart_item_data ) {
global $woocommerce;
// Some MYSQL to check if product was bought before
if ($bought_before == 'true') {
$woocommerce->cart->empty_cart();
}
// Echo some text to explain why you can only buy the product once
return $cart_item_data;
}
Run Code Online (Sandbox Code Playgroud)