I am new to woocommerce so I need you help to findout the issue i am trying to solve from last 3 days. In short, I have a pizza store at 5 locations. There is a minimum order per location. In checkout I made a custom city select option field based on it total bill will be accepted or rejected. I am using checkout manager. Its really confusing.
So my question is how can I do this and achieve this result. I don't want to hard code everything because In future locations might change.
Any solution for this problem. Thanks In advance.
function check_min_order($order_id) {
global $woocommerce;
$order = new WC_Order($order_id);
$total = $order->calculate_totals();
if (!$total > 'YOUR MINIMUM AMOUNT HERE') {
wc_add_notice( 'You did not meet the minimum order total.', 'error' );
exit;
}
}
add_action( 'woocommerce_checkout_order_processed', 'check_min_order', 1, 1 );
Add this to your functions.php
I might have the $total variable being set using the wrong command. But this should give you a general idea of how to acheive this. It interupts the order process and checks the total to see if it meets your minimum amount. You can create a series of if statements or a switch statement for each case in your form fields. Whatever the name of the request object for the city is you can use $_REQUEST['your_city_field_name'] to get the value.
If the condition is met then it will return a woocommerce formatted error and stop the processing of the transaction. If not it will continue as normal.
Related
I am having an issue since reverting my site to a history state in which the $order_id was also reverted; however my 3rd party stock management has used a bunch of order Id's, about 100 out that will create a problem when I get to them and orders are re-made using old ID's that are already in the system.
I need to increase the count of the $order_id as to avoid this; seems easy enough but I have found NO support relating to this aside from digging around in the database and that seems unessisairy for something this simple.
I can manipulate the order number using the commonly found "add prefix or suffix to order number" but that affects all orders, past and future. So if I add a 0 to the end; all the old orders in the system suddenly also have a 0 added and it breaks the links to the external api managing the orders.
I need a way to just increase the $order_id by 100 ONLY on newly generated orders. I guess I could go post 100 articles or something tedious like that but I feel there should be a rather simple way to just increase the count on the site. Skip a few numbers then good to go y'know?
here is the code I used that changes all the orders; it is not helpful really but I mentioned it so here it is:
add_filter( 'woocommerce_order_number', 'test_woocommerce_order_number', 1, 2 );
function test_woocommerce_order_number( $oldnumber, $order ) {
$prefix = "AU-";
$suffix = 0;
return $prefix . $order->id . $suffix;
}
This will change my order number from 10338 to: AU-103380 BUT it changes all orders in the system. I simply want to increase the counter so that new orders begin at 10438.
In the end I simply made a hidden post and saved it 100 times. If you run into this issue and you need to skip 1,000 or 10,000+ values of the $order->id then my solution will not work for you. This worked for me; however "workaround-y" it may be.
I´m working on a solution to change the tax class based on the country of the customer AND if he can provide a VAT-ID or not.
The store is EU based and providing services to B2B and B2C.
So for all EU based companies that can provide a VAT-ID, no taxes will be charged unless the origin country is the same.
For all customers who cannot provide a VAT-ID, our local taxes will be added.
And so on...
All solutions I have found are only interacting with the cart, but as I´m creating the order programmatically I need another solution.
Is there a way (a hook maybe) to change the tax_class while creating the order?
For testing I tried to add this method but that did not work. It fires the filter but does not change the tax class in the order.
function wc_change_tax_class( $tax_class, $product ) {
$tax_class = 'Zero rate';
return $tax_class;
}
add_filter( 'woocommerce_product_get_tax_class', 'wc_change_tax_class', 1, 2 );
add_filter( 'woocommerce_product_variation_get_tax_class', 'wc_change_tax_class', 1, 2 );
Also I tried this method in the function that creates the order but with the same result. Nothing happend.
$woocommerce->customer->set_is_vat_exempt( true );
Thanks for any help!
After hours of trying to find the reason, the solution was quite easy:
All solutions I found suggested to write 'Zero rate' or 'Zero Rate'. Depending on what the Name was given in the Woocommerce settings. But for me, it does only work if you write it this way 'zero-rate'. So change the table class name and remove any spaces in the woocommerce settings and of course in the variable.
$tax_class = 'zero-rate';
Hope that saves someone's time!
I'm using WooCommerce Subscriptions/Memberships and am pretty certain what I'm trying to achieve isn't possible out of the box. Essentially I want three options of billing intervals:
$15 per week for 12 weeks.
$60 per month for 3 months.
$180 up front.
I know how to do the above using Variable Subscriptions, however the problem is that I need it to change over to $9.95 per week for all three of the above after 12 weeks is up. Does anyone have any ideas about how to achieve this?
I've done something similar, but on different trigger. Anyway, I changed the product inside the subscription. All you need to do is to create another product, with the $9.95/week, and when the time comes, change the base product in the subscription, recalculate totals, setup the period and interval and save.
You need to hook woocommerce_subscription_status_expired which passes the subscription, and then manipulate the subscription. something like:
add_action( 'woocommerce_subscription_status_expired', 'change_subscription_base_product', 10, 1 );
function change_subscription_base_product($subscription){
$subscription->remove_order_items();
$args = array(); //you can change here to total etc..
$productId = 123;/Change this to be dynamic or to hard coded product ID
$product = wc_get_product($productId);
$subscription->add_product($product, 1, $args);
$subscription->calculate_totals();
$subscription->set_billing_period(WC_Subscriptions_Product::get_period($productId));
$subscription->set_billing_interval(WC_Subscriptions_Product::get_interval($productId));
$subscription->save();
}
I have an online store where customers place an order and it is done with payment as COD. It is integrated with our warehouse management where it will export all the orders at the end of the day to the system from the site.
The status of the orders places are processing.
I am trying to make a php cron job where the order status of all these order set as completed when the list of orders are exported.
I have looked at various solutions and all change the order status at the time of placing the order while i want it later, once the data is exported.
If somebody can help me with the php function that sets all the order in the woocommerce to "complete" at some trigger, I would be really grateful.
In your cron function you may have a loop to get the order ID that needs to be exported, so just pass the Order ID to the given function it'll update the Order Status to wc-complete, you can also pass an order note if you need.
function wh_mark_order_as_omplete($order_id, $note = '')
{
//this check is option if you do not need this you can remove it.
//for COD order only
if ('cod' != get_post_meta($order_id, '_payment_method', true))
return;
$order = wc_get_order($order_id);
if (empty($note)):
$order->update_status('completed');
else:
$order->update_status('completed', $note);
endif;
}
Hope this helps!
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