Php 电子商务电报通知
我正试图用电报通知新订单。 除了订单上的产品清单,我几乎得到了我想要的所有细节。如果我在WordPress中使用短代码公开订单详细信息,我的代码就正常工作了。当我试图在电报中这样做时,产品的详细信息就不再显示了 这是我的密码:Php 电子商务电报通知,php,wordpress,woocommerce,telegram,hook-woocommerce,Php,Wordpress,Woocommerce,Telegram,Hook Woocommerce,我正试图用电报通知新订单。 除了订单上的产品清单,我几乎得到了我想要的所有细节。如果我在WordPress中使用短代码公开订单详细信息,我的代码就正常工作了。当我试图在电报中这样做时,产品的详细信息就不再显示了 这是我的密码: add_action( 'woocommerce_new_order', 'telegram_notification', 1, 1 ); function telegram_notification( $order_id ) { $orde
add_action( 'woocommerce_new_order', 'telegram_notification', 1, 1 );
function telegram_notification( $order_id ) {
$order = wc_get_order( $order_id );
$text = "*" . __( 'New Order') . "*\n\n";
$text .= __( 'Order number') . ': ' . $order_id . "\n";
$text .= __( 'Status') . ': ' . wc_get_order_status_name( $order->get_status() ) . "\n";
$text .= __( 'Date') . ': ' . $order->get_date_modified() . "\n";
$text .= __( 'Email') . ': ' . $order->get_billing_email() . "\n";
$text .= __( 'Total price') . ': ' . $order->get_total() . "\n";
$text .= __( 'Payment method') . ': ' . $order->get_payment_method_title() . "\n";
$text .= "\n" . __( 'Items') . ':' . "\n";
foreach ( $order->get_items() as $item_id => $item_data ) {
$product = $item_data->get_product();
$product_name = $product->get_name();
$item_quantity = $item_data->get_quantity();
$item_total = $this->wc_price( $item_data->get_total() );
$text .= $product_name . ' × ' . $item_quantity . ' = ' . $item_total . "\n";
}
$xsl = file_get_contents("https://api.telegram.org/bot12345:xxxxx-zzzzz/sendMessage?parse_mode=html&chat_id=-1234567890&text=" . $text);
}
以下是电报中的结果:
新订单号:981订单号:Platăn așteptareău日期:2020-12-12T12:12:12 00:00电子邮件:email@yahoo.com_Total价格:10.00欧元付款方式:Livreare欧元项目:_
项目上没有显示任何内容
我的WooCommerce版本是4.1.0,WordPress版本是5.4.1
提前感谢您抽出时间您是如何解决问题的?我在这里找到了解决方案
// Get and Loop Over Order Items
foreach ( $order->get_items() as $item_id => $item ) {
$product_id = $item->get_product_id();
$variation_id = $item->get_variation_id();
$product = $item->get_product();
$name = $item->get_name();
$quantity = $item->get_quantity();
$subtotal = $item->get_subtotal();
$total = $item->get_total();
$tax = $item->get_subtotal_tax();
$taxclass = $item->get_tax_class();
$taxstat = $item->get_tax_status();
$allmeta = $item->get_meta_data();
$somemeta = $item->get_meta( '_whatever', true );
$type = $item->get_type();
}