WC_Order get_items () and their number

I am trying to create an application that tells me my trade order, order items and quantity,

I'm 90% there

function custom_woocommerce_complete_order_sms( $order_id ) { global $woocommerce; if ( !$order_id ) return; $order = new WC_Order( $order_id ); $product_list = ''; $order_item = $order->get_items(); foreach( $order_item as $product ) { $prodct_name[] = $product['name']; } $product_list = implode( ',\n', $prodct_name ); require "twilio-php-master/Services/Twilio.php"; $AccountSid = "xxxxxxxxx"; $AuthToken = "xxxxxxxxx"; $client = new Services_Twilio($AccountSid, $AuthToken); $people = array( "xxxxxxxxxx" => "Me", ); foreach ($people as $number => $name) { $sms = $client->account->messages->sendMessage( "+44xxxxxxxxxx", // the number we are sending to - Any phone number $number, // the sms body "Hey $name, there is a new Order, the order is, $product_list" ); } } 

My problem is that I do not know how to get the Number element, for example, my text looks like a list, paragraph 1, paragraph 2, paragraph 3, I want him to say paragraph 1 x1, paragraph 2 x2, item3 x3

I tried to look into the email php file in the abstract woo commerce folder to see how they arrive when they send the quantity in emails, but lost a little

also in WC_Abstract_Order class, the only thing I could find was get_item_total , which returns the total number of all elements

+7
php woocommerce
source share
2 answers

From the study you can also take qty from the order item

  $product['qty']; 

Therefore, it was just iterate over and add the quantity to the element name (below)

 $product_details = array(); $order_items = $order->get_items(); foreach( $order_items as $product ) { $product_details[] = $product['name']."x".$product['qty']; } $product_list = implode( ',', $product_details ); 
+14
source share

this is not so much an addition to the answer as an additional question. I used to program PHP and SQL "back to day" before everything got so OOP crazy. Therefore, I sometimes have problems even finding what I want to edit. In addition, I hesitate to mess with the PHP code, as any error can cause WordPress to crash. I would also like my changes to be saved and not overwritten when updating WordPress or the plugin.

So what are some tips on where to go to find out more?

Also, the code on this page is very close to what I want to do. I installed the woocommerce plugin for the cost of goods and would like to use the new "cost of goods" field when calculating the final prices, but ONLY for the email that I want to send to my supplier.

For the time being, I will be fine just by changing the order notification email and contacting my supplier. However, I would like to be able to add providers (I will probably use the WooCommerce Dropship plugin) and use this calculation for suppliers, but not for my customers.

I suppose I might need some kind of if then else expression, and then create a custom version of get_items (), but, as I said, I'm 20 years behind this stuff, so I'm going to need to be driven with my nose on it until I pick up speed.

Thanks!

0
source share

All Articles