php – WC_Order get_items()及其数量
发布时间:2020-12-13 18:08:00 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试构建一个应用程序,它将我的商业订单,订单商品和数量发给我, 我90%在那里, function custom_woocommerce_complete_order_sms( $order_id ) { global $woocommerce; if ( !$order_id ) return; $order = new WC_Order( $order_id ); $product_list
我正在尝试构建一个应用程序,它将我的商业订单,订单商品和数量发给我,
我90%在那里, 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" ); } } 我的问题是我不知道如何获取项目数量,例如我的文字看起来像列表,项目1,项目2,项目3,我想要说项目1 x1,项目2 x2,项目3 x3 我确实尝试挖掘抽象woo commerce文件夹中的电子邮件php文件,看看他们如何做,因为他们在电子邮件中发送数量,但有点丢失 同样在类WC_Abstract_Order中我唯一能找到的东西是get_item_total,它返回所有项目的总和
通过研究,您还可以从订单商品中获取数量
$product['qty']; 因此,循环并将数量添加到项目名称很简单(下面) $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 ); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |