![](/img/trans.png)
[英]How to add a custom shortcode below the product table on woocommerce checkout page
[英]How to Define Product in WooCommerce Shortcode to use on Custom Order Received Page
根据我之前的问题为什么 WooCommerce Order Shortcode Generate Plugin Notice on CustomThank You Page?
通知消息已更改,现在它要求我定义产品。 这是通知:
Notice: Undefined variable: product in /wp-content/themes/storefront/functions.php on line 842
该通知指的是这一行:
'purchase_note' => $product ? $product->get_purchase_note() : '',
这是完整的代码:
function order_cost_breakdown(){
if ( isset( $_GET['order_id']) && $_GET['order_id'] > 0 ) {
$order_id = (int) esc_attr( $_GET['order_id'] );
$order = wc_get_order( $order_id );
$order_data = $order->get_data();
$show_purchase_note = $order->has_status( apply_filters( 'woocommerce_purchase_note_order_statuses', array( 'completed', 'processing' ) ) );
ob_start();
?>
<div class="woocommerce-account woocommerce-page"><div class="woocommerce">
<table class="shop_table order_details">
<thead>
<tr>
<th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ( $order->get_items() as $item_id => $item ) {
wc_get_template( 'order/order-details-item.php', array (
'order' => $order,
'item_id' => $item_id,
'item' => $item,
'product' => apply_filters( 'woocommerce_order_item_product', $item->get_product( $item ), $item ),
'show_purchase_note' => $show_purchase_note,
'purchase_note' => $product ? $product->get_purchase_note() : '',
) );
}
?>
<?php do_action( 'woocommerce_order_items_table', $order ); ?>
</tbody>
<tfoot>
<?php
foreach ( $order->get_order_item_totals() as $key => $total ){
?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
?>
</tfoot>
</table>
</div>
</div>
<?php
return ob_get_clean();
}
}
任何建议都是有帮助的,因为我显然不是专家。
修复通知
代替
<?php foreach ( $order->get_items() as $item_id => $item ) {
wc_get_template( 'order/order-details-item.php', array (
'order' => $order,
'item_id' => $item_id,
'item' => $item,
'product' => apply_filters( 'woocommerce_order_item_product', $item->get_product( $item ), $item ),
'show_purchase_note' => $show_purchase_note,
'purchase_note' => $product ? $product->get_purchase_note() : '',
) );
}
?>
和
<?php foreach ( $order->get_items() as $item_id => $item ) {
$product = $item->get_product();
wc_get_template( 'order/order-details-item.php', array (
'order' => $order,
'item_id' => $item_id,
'item' => $item,
'product' => apply_filters( 'woocommerce_order_item_product', $item->get_product( $item ), $item ),
'show_purchase_note' => $show_purchase_note,
'purchase_note' => $product ? $product->get_purchase_note() : '',
));
}
?>
这应该足够了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.