I am looking to update the price of a product AFTER it has been purchased.
The idea is that when a product has been sold a specific amount of times, the price would be programatically raised to a predetermined amount.
I found the woocommerce_payment_complete hook, which looks like it will get me into the right spot to make the update, but I can't find a function that will update the price.
I do believe I found it!
update_post_meta($post_id, '_regular_price', '10'):
Related
First of all, thank you for your support all those years.
I am building a role-based pricing plugin for a client and I am having an existential crisis over filters WooCommerce uses for prices. I made this post in hope someone can explain this so someone in the future can find this post.
I managed to understand how filters for simple products work but I don't have an idea how equivalent filters for variable products work
Simple products
As from what I understood, you can override price, regular price, and sale price for simple products returning some value inside filters woocommerce_product_get_price, woocommerce_product_get_regular_price, and woocommerce_product_get_sale_price. Those filters will save provided data into $product object and you can easily access them later in woocommerce_get_price_html filter by using $product->get_regular_price
Variable products
Looks like variable products work differently. For example, they dont save overriden price to $product or $variation object and you cannot fetch overriden prices by calling $variation->get_regular_price.
As I understood, following filters change price of the product on add-to-cart variation select, and in the cart and do not save them in $variation object.
woocommerce_product_variation_get_price
woocommerce_product_variation_get_regular_price
woocommerce_product_variation_get_sale_price
I didnt manage to fully understand what following filters do. But when I turn them on loop price changes and product price changes but prices are removed from add-to-cart select and cart prices are not changed.
woocommerce_variation_prices_price
woocommerce_variation_prices_regular_price
woocommerce_variation_prices_sale_price
I would like to know some questions. We have a school where in a short time we will begin to enroll people online, especially with the Covid-19. We only charge 1 tuition even if the same student enrolls in several options. So I would like the final price to be the same regardless of the quantity of items. Well, I have found a code that solves me in part since the coupons do not work for me, discounts do not apply this for me, as a last option I could be worth it temporarily:
add_filter( 'woocommerce_calculated_total', 'change_calculated_total', 10, 2 );
function change_calculated_total( $total, $cart ) {
return $total = 40;
}
So if there are 3/4 (maximum number of items admitted to the basket) they will only pay 40€
This code is from here: Change Cart total using Hooks in Woocommerce 3.2+
This option is not the most correct, since it does not show a discount, it simply "tricks the system". But I would like this rule to affect the articles of a specific categories, only the enrollment, but the rest of the items in my store in other categories are charged at normal price. Could you please help me those 2 questions? Thanks in advance
i am creating a custom button to add products to cart using add_to_cart($product_id, $quantity) function. It's working well for the single property but when I change product_id with another product id then it shows error.
$cart = $woocommerce->cart->add_to_cart($product_id, $quantity);
when I try same with different product_ids it stops working.
any solution?
Okay, thanks for the help. Finally, the problem is solved. Actually, 93 product_id product is out of stock that's why it returns false. add_to_cart() function does not work with a product out of stock.
Using three plugins:
WooCommerce
Subscriptio
WooEvents
I have created a product which allows for a customer to pay for an event over five instalments.
A customer has placed an order and made their first of the five payments via PayPal and has then contacted me to advise they have booked the wrong event.
The correct event is exactly the same except the dates are a month sooner.
I have added the following snippet to be able to edit 'processing' orders:
add_filter( 'wc_order_is_editable', 'wc_make_processing_orders_editable', 10, 2 );
function wc_make_processing_orders_editable( $is_editable, $order ) {
if ( $order->get_status() == 'processing' ) {
$is_editable = true;
}
return $is_editable;
}
From the order screen within the back-end of WordPress I can see that the the order can be edit by way of removing the product from the order or editing the meta data and cost.
The correct product that should have been ordered has a different product/variation ID.
My question is simply:
Should I remove the incorrectly ordered product from the order and add the correct product (both have the same properties with the exception of the courses dates); or
Should I just change the meta data and increase the stock levels for the incorrectly product back to X and reduce the stock level for the correct product?
Your second option is much better. Change the meta from database if its accessible and then manage the stock accordingly.
I have not yet done this, but according to this exchange ...
How can I add a product to an existing and paid Woocommerce order?
... you can set the order status to "On Hold" and make changes to the order itself. I presume you would then return the status to "Processing".
I would expect that if the application permits those changes, then it would be doing the background meta changes to inventory levels, etc., and spare you the problem of doing so (and the potential errors that may occur when messing with the data tables outside of the application).
Like I said, I haven't done this. But it might be worthwhile doing a little test to make sure it works as it seems to be described in the answer to the other question.
J
I am using woocommerce table rate shipping
In my current system I need to two types of shipping rates
1. Per Order (Based on category )
2. Per Item (Based on category )
The both categories are working fine if the products are separately added
But while I am adding and one products from each categories, in that senarioes I want to both shipping method summation.
Can anyone help me?
Thanks,
Denis
http://www.yiion.com
If you are using the Table Rate plugin from WooCommerce you have to check 'break' when setting up the shipping method.