【发布时间】:2019-08-12 18:35:57
【问题描述】:
以下 Woocommerce 代码,允许在购买后再次购买
function sv_disable_repeat_purchase( $purchasable, $product ) {
// Enter the ID of the product that shouldn't be purchased again
$non_purchasable = 40021;
// Get the ID for the current product (passed in)
$product_id = $product->is_type( 'variation' ) ? $product->variation_id : $product->id;
// Bail unless the ID is equal to our desired non-purchasable product
if ( $non_purchasable != $product_id ) {
return $purchasable;
}
// return false if the customer has bought the product
if ( wc_customer_bought_product( wp_get_current_user()->user_email, get_current_user_id(), $product_id ) ) {
$purchasable = false;
}
// Double-check for variations: if parent is not purchasable, then variation is not
if ( $purchasable && $product->is_type( 'variation' ) ) {
$purchasable = $product->parent->is_purchasable();
}
return $purchasable;
}
add_filter( 'woocommerce_variation_is_purchasable', 'sv_disable_repeat_purchase', 10, 2 );
add_filter( 'woocommerce_is_purchasable', 'sv_disable_repeat_purchase', 10, 2 );
请有人帮我将 $non_purchasable = 40021 更改为一系列产品
【问题讨论】:
标签: php arrays wordpress woocommerce product