0

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

2
  • 1
    Do you get any error? How do you know 'something does not work'?
    – Ruvee
    May 19, 2021 at 16:43
  • 4 of my products should be on sale, but nothing happens on my website...
    – Luc Mosser
    May 19, 2021 at 20:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy