I try to get all my product ids in an array which I can use to choose 4 random products every day.
There is my function, but something does not work... It's probably a problem with wc_get_products, but I don't really understand the problem.
function periodic_discount_prices( $price, $product, $parent = 0 ){
// Get all the product Ids in an array
$ids = wc_get_products( array( 'return' => 'ids', 'limit' => -1 ) );
// Set the product Ids that will be discounted
$discounted_products = array_rand( $ids, 4 );
if( get_discount_period_rate() && in_array( $product->get_id(), $discounted_products ) ){
$price = $product->get_regular_price() * get_discount_period_rate();
}
return $price;
}
Thanks for your help