1

I have a product (course) that loses value the closer it gets to the end of term. I've set up 'End date' and 'Weekly price' as custom fields on a page, and can calculate the exact price to pay in PHP.

How do I dynamically create a woocommerce product, or change an established product's price based on the 'Time Left' calculation I performed?

I've tried changing 'price.php' in Woocommerce's template file, but apparently it's just a cosmetic change, and the price reverts to original at basket and checkout.

Haven't the foggiest where else to start, so many thanks in advance.

1

Ok! This is my solution, and (so far) it works:

function return_custom_price($price, $product) {

    $myPrice = 15;

    global $current_user;
    $price = $myPrice;
    $post_id = $post->ID;
    return $price;
}
add_filter('woocommerce_get_price', 'return_custom_price', 10, 2);

It does target every single product in the store, but as the site only has one product, this works fine.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.