Php 自定义商业电子邮件:获取产品缩略图和价格
我最近刚刚为Woocommerce创建了定制电子邮件。除了一个问题外,我什么都做得很好。在我带来/获得“产品形象”之前,我能够毫无问题地加载“产品价格” 然而,现在我得到的产品形象,我有麻烦获得“产品价格”和订单没有处理和完成 下面是我用来收集电子邮件中显示的所有信息的PHP代码Php 自定义商业电子邮件:获取产品缩略图和价格,php,wordpress,object,woocommerce,product,Php,Wordpress,Object,Woocommerce,Product,我最近刚刚为Woocommerce创建了定制电子邮件。除了一个问题外,我什么都做得很好。在我带来/获得“产品形象”之前,我能够毫无问题地加载“产品价格” 然而,现在我得到的产品形象,我有麻烦获得“产品价格”和订单没有处理和完成 下面是我用来收集电子邮件中显示的所有信息的PHP代码 <?php foreach ($order->get_items() as $theitem_id => $theitem ) { // PRODUC
<?php
foreach ($order->get_items() as $theitem_id => $theitem ) {
// PRODUCT NAME
$product_name = $theitem->get_name();
// PRODUCT QUANTITY
$quantity = $theitem->get_quantity();
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $theitem->get_subtotal();
$item_subtotal = number_format( $item_subtotal, 2 );
// LINE ITEM TOTAL (discounted)
$item_total = $theitem->get_total();
$item_total = number_format( $item_total, 2 );
$product_id = $theitem['product_id'];
$product = wc_get_product( $product_id );
// PRODUCT IMAGE
$prodimage = $product->get_image( array( 200, 200 ) )
// PRODUCT PRICE
$product_price = $product->get_price();
?>
我相信我离这一点不远了,因为当我注释掉“产品价格”PHP代码时,一切都很好(没有明显的价格收集)
任何帮助都会很好,非常感谢因为Woocommerce 3,产品ID错误(还有产品对象)…请尝试:
<?php
// Loop through order items
foreach ($order->get_items() as $item_id => $item ) {
// PRODUCT NAME
$product_name = $item->get_name();
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $item->get_subtotal();
$item_subtotal = number_format( $item_subtotal, 2 );
// LINE ITEM TOTAL (discounted)
$item_total = $item->get_total();
$item_total = number_format( $item_total, 2 );
// Get an instance of the product Object
$product = $item->get_product(); // <==== HERE
$product_id = $product->get_id(); // <==== and HERE
// PRODUCT IMAGE
$product_image = $product->get_image( array( 200, 200 ) );
// PRODUCT PRICE
$product_price = $product->get_price();
?>
它现在应该能更好地工作了
相关:自Woocommerce 3以来,产品ID错误(以及产品对象)…请尝试:
<?php
// Loop through order items
foreach ($order->get_items() as $item_id => $item ) {
// PRODUCT NAME
$product_name = $item->get_name();
// PRODUCT QUANTITY
$quantity = $item->get_quantity();
// LINE ITEM SUBTOTAL (Non discounted)
$item_subtotal = $item->get_subtotal();
$item_subtotal = number_format( $item_subtotal, 2 );
// LINE ITEM TOTAL (discounted)
$item_total = $item->get_total();
$item_total = number_format( $item_total, 2 );
// Get an instance of the product Object
$product = $item->get_product(); // <==== HERE
$product_id = $product->get_id(); // <==== and HERE
// PRODUCT IMAGE
$product_image = $product->get_image( array( 200, 200 ) );
// PRODUCT PRICE
$product_price = $product->get_price();
?>
它现在应该能更好地工作了
相关:可能只是没有设置?尝试$product->get_常规价格()或$product->get_销售价格(),可能只是没有设置?尝试$product->get_regular_price()或$product->get_sale_price(),不幸的是,这似乎不起作用。当我使用这段php代码时,在我提交地址详细信息后,我下的订单处理不正确。@user3060945这是正确的方法,所以其他东西在制造麻烦。您应该在问题中提供更多的上下文和完整的代码……不幸的是,这似乎不起作用。当我使用这段php代码时,在我提交地址详细信息后,我下的订单处理不正确。@user3060945这是正确的方法,所以其他东西在制造麻烦。你应该在你的问题中给出更多的上下文和完整的代码…