Get orders shipping items details in WooCommerce 3

If you want to get the Order Items Shipping data, you need first to get them in a foreach loop (for ‘shipping’ item type) and to use WC_Order_Item_Shipping methods to access data $order_id = 528; // For example // An instance of $order = wc_get_order($order_id); // Iterating through order shipping items foreach( $order->get_items( ‘shipping’ ) … Read more

Get coupon data from WooCommerce orders

Update 3 Since WooCommerce 3.7, you should now use the WC_Abstract method get_coupon_codes() on the WC_Order instance object to get the used coupons from an order, as get_used_coupons() method is deprecated. So you will replace in the code: foreach( $order->get_used_coupons() as $coupon_code ){ by: foreach( $order->get_coupon_codes() as $coupon_code ){ Then you can get coupon details … Read more

Create an order programmatically with line items in Woocommerce 3+

With latest version of WooCommerce is possible try this as something like $address = array( ‘first_name’ => ‘Fresher’, ‘last_name’ => ‘StAcK OvErFloW’, ‘company’ => ‘stackoverflow’, ’email’ => ‘[email protected]’, ‘phone’ => ‘777-777-777-777’, ‘address_1′ => ’31 Main Street’, ‘address_2’ => ”, ‘city’ => ‘Chennai’, ‘state’ => ‘TN’, ‘postcode’ => ‘12345’, ‘country’ => ‘IN’ ); $order = wc_create_order(); … Read more

Change COD default order status to “On Hold” instead of “Processing” in Woocommerce

Updated: The code that you found in Github is outdated, clumsy and complicated, since there is a dedicated filter hook now. You should better try this lightweight and effective code, that will set the default order status for “Cash on delivery” payment gateway (COD) to “On Hold”: add_filter( ‘woocommerce_cod_process_payment_order_status’, ‘change_cod_payment_order_status’, 10, 2 ); function change_cod_payment_order_status( … Read more

Check if a user/guest has purchased specific products in WooCommerce

Lighter and improved code version in HERE that handle multiple product IDs Updated (compatibility for Woocommerce 3+) Yes it’s possible, writing a conditional function that returns “true” if current customer has already bought specifics defined products IDs. This code goes on function.php file of your active child theme or theme. Here is the conditional function: … Read more

Woocommerce: Which hook to replace deprecated “woocommerce_add_order_item_meta”

2017/2018 THE RIGHT WAY (Using new CRUD setters and Getters methods) Related: Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4 Since woocommerce 3 that has improved many things making drastic changes, the action hook woocommerce_add_order_item_meta still work perfectly even in woocommerce version 3.3+. This hook is enabled by WC_Checkout class methods and related functions in the checkout … Read more