The only calculate_shipping() methods I’ve found belong to WC_Cart and WC_Order.
When I attempted to use WC_Cart for this (via WC()->cart), it ended up interfering with customers using the cart on the front end, which is obviously totally unacceptable.
From what I can tell, it looks like WC_Order->calculate_shipping() automatically saves an order to the database, which I expect would result in our database quickly getting filled up with garbage orders by this backend process.
There has to be a better way to do this. How can I simply run the shipping calculation without generating side effects?
Thank you.
]]>$order = new WC_Order($order_id);
print_r($order)
But it returns the error:
Fatal error: Uncaught Exception: Invalid Order. in /var/www/vhosts/tbai.facturaone.com/httpdocs/wp-content/plugins/woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php:104
Looking inside the file I see inside line abstract-wc-order-data-store-cpt.php:104:
if ( ! $order->get_id() || ! $post_object || ! in_array( $post_object->post_type, wc_get_order_types(), true ) ) {
wc_get_order_types() is an empty array, and never compare with a “shop_order”
thanks for your valuable help
]]>I cant really find out, wheter is woocommerce or 10.9 jetpack causes the crash.
After activating the two pluging, i am not able to get the health check, so the only error i get, is from e-mail:
Fehler-Details
==============
Ein Fehler vom Typ E_ERROR wurde in der Zeile 18 der Datei /var/www/vhosts/flatee.ch/httpdocs/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Overrides/Order.php verursacht. Fehlermeldung: Uncaught Error: Class 'WC_Order' not found in /var/www/vhosts/flatee.ch/httpdocs/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Overrides/Order.php:18
Stack trace:
#0 /var/www/vhosts/flatee.ch/httpdocs/wp-content/plugins/jetpack/vendor/jetpack-autoloader/class-php-autoloader.php(90): require()
#1 [internal function]: Automattic\Jetpack\Autoloader\jpf11009ded9fc4592b6a05b61ce272b3c_jetpack?10_9\PHP_Autoloader::load_class()
#2 [internal function]: spl_autoload_call()
#3 /var/www/vhosts/flatee.ch/httpdocs/wp-includes/functions.php(642): unserialize()
#4 /var/www/vhosts/flatee.ch/httpdocs/wp-includes/option.php(228): maybe_unserialize()
#5 /var/www/vhosts/flatee.ch/httpdocs/wp-includes/cron.php(1170): get_option()
#6 /var/www/vhosts/flatee.ch/httpdocs/wp-includes/cron.php(765): _get_cron_array()
#7 /var/www/vhosts/flatee.ch/httpdocs/wp-includes/cron.php(817): wp_get_scheduled_event()
#8 /var/www/vhosts/flatee.ch/httpdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/jetpack-waf/actions.php
]]>I did a test and copied one of them onto another browser not logged in and yeah I was able to download the file.
At first, I was thinking it’s IP-based and it’s not. I tried my phone with a different IP and I was still able to download the file with the same wc_order link. I also tried another computer with a different ISP line and still able to download it.
This needs to be fixed. This grants someone the option to download the file without even logging in and paying for it.
]]>But how i can do?
thanks!
]]>$user = wp_get_current_user();
$order = new WC_Order();
$order->set_customer_id($user->ID);
$product = wc_get_product(123);
$order->add_product($product);
$order->save();
Is there a way to generate also the invoice details (Invoice Number and Invoice Date)?
Image: https://i.ibb.co/yqRDXzS/2019-05-17-02-39-44.png
Thank you,
Yiannis
]]>I’ve tried modifying the total within the WC_Order during the payment process as well as modifying the WC_Cart and had no luck. Any suggestions?
]]>I do the following:
$old_order = wc_get_order($old_order_id);
duplicate_line_items($new_order, $old_order);
//re-fetch order to make sure changes aren't lost.
$new_order = $wc_get_order($new_order->get_id());
$new_order->calculate_totals();
$new_order->save_meta_data();
$new_order->save();
My duplicate_line_items function looks like this:
function duplicate_line_items($source_order, $new_order){
foreach ($source_order->get_items() as $item){
$new_order->add_item($item);
}
$new_order->apply_changes();
$new_order->save();
}
When I run this code, the items do not display in the admin view of the “new” order (the destination order), nor do they show up in the database (select * from wp_woocommerce_order_items WHERE order_id = <destination order post id>).
I do see that per the WC_Order::add_item()
docs, “The order item will not persist until save.”, but i am saving the order, several times.
Am I missing a step here or something?
Thanks!
]]>I’m trying to use this plugin https://github.com/Neuralab/WooCommerce-Salesforce-integration.
However i’m getting an error on bstract-wc-legacy-order.php in line 630 in the init method, on this line ” $this->data_store->read( $this );”
saying that the data_store is empty.
Someone knows how to fix this?
]]>I’ve just upgraded Woocommerce to v 3.03
I’m having trouble with a line of code:
$original_order = new WC_Order($original_order_id);
Which is giving
Fatal error: Uncaught Exception: Invalid order. in /home/developer1181/weirdsky.dreamhosters.com/goldenmean/wp-content/plugins/woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php:86
The order_id I’m giving it is valid, and this piece of code used to work before the upgrade.
Any ideas as to what has happened?
Nick
]]>