首页 > 解决方案 > 如何从 WooCommerce 订单中获取选定数量的产品?

问题描述

我目前正在开发一个使用 WooCommerce 的 WordPress 项目。我正在尝试制作一个客户可以用来退款订单的表格,而我现在还很遥远。我要解决的一件事是,是否可以让客户选择他们想要退货的精选产品?

下面我使用 WooCommerce 自己的功能来打印所选订单的信息。在这里,我想添加一个可能的输入,让客户选择他们想要退货的商品数量,但我不确定如何退货。

同样用于上下文:这是第二页,它向用户显示他使用此订单订购了哪些商品。在第一页上,客户被询问他们的信息以确保这是他们的订单。在第三页也是最后一页上,用户确定他们想要提出退款请求,以及是否想要发表评论。

$order = wc_get_order( $ordernumber );
foreach ($order->get_items() as $item ) {
    $unitprice = $item->get_total() / $item->get_quantity();
    echo "<input type='checkbox' name='productinfo[]' value='" .$item->get_name() . "|" . $item->get_quantity() . "|" . $item->get_total() ."'>";
    echo '<p>';
    echo __('Tuotteen nimi: ' ) . $item->get_name() . '<br>';
    if($item->get_quantity() > 1) {
        echo "Määrä: " . "<input type='number' name='numberqty' value='" . $item->get_quantity() . "'max='" .$item->get_quantity() . "' min='0' > " . "<br/>";
    } else {
        echo __('Määrä: ' ) . $item->get_quantity() . '<br>';
    }
    if ($item->get_quantity() > 1) {
        echo __('Tuotteen kappalehinta: ') . $unitprice . '€' . '<br/>';
    }
    echo __('Tuotteiden kokonaishinta: ' )  . wc_price($item->get_total()) . '</p>' . '<br/>';
}
echo '<p>'. __('Tilauksen yhteishinta: ') . $order->get_total() . '</p>';

如果有人至少可以为我指出正确的方向,我将不胜感激。先感谢您!

标签: phpwordpresswoocommerce

解决方案


推荐阅读