将装运计算器添加到woocommerce订单页面

将装运计算器添加到woocommerce订单页面,woocommerce,Woocommerce,在Woocommerce的“编辑订单”页面上,是否有任何方式显示该订单的所有发货方式及其成本?有点像客户在购物车页面或结帐页面上看到的发货计算器,而是在编辑订单页面上看到的 或者,将订单中的所有项目和客户配送邮编等添加回新的购物车会话,以便我们可以使用此数据在购物车页面中查看配送计算器 使用以下方法从订单中提取产品: $order_items = $order_object->get_items( array('line_item', 'fee', 'shipping') ); if (

在Woocommerce的“编辑订单”页面上,是否有任何方式显示该订单的所有发货方式及其成本?有点像客户在购物车页面或结帐页面上看到的发货计算器,而是在编辑订单页面上看到的

或者,将订单中的所有项目和客户配送邮编等添加回新的购物车会话,以便我们可以使用此数据在购物车页面中查看配送计算器

使用以下方法从订单中提取产品:

$order_items = $order_object->get_items( array('line_item', 'fee', 'shipping') );
if ( !is_wp_error( $order_items ) ) {
foreach( $order_items as $item_id => $order_item ) {
    echo $order_item->get_quantity(); // or $order_item['quantity'];
    echo $order_item->get_product_id(); // or $order_item['product_id'];
    echo $order_item->get_variation_id(); // or $order_item['variation_id'];
    echo $order_item->get_product(); // get the associated product
}
}
然后wp_create_order()将它们添加到新购物车


非常感谢

我找到了这段代码,这是否适用于现代版本的woocommerce

// Post variables
$order_id   = isset($_POST['order_id'])?$_POST['order_id']:0;
$country    = isset($_POST['country'])?$_POST['country']:0;
$state      = isset($_POST['state'])?$_POST['state']:0;
$postcode   = isset($_POST['postcode'])?$_POST['postcode']:0;
$city       = isset($_POST['city'])?$_POST['city']:0;

// Order and order items
$order          = wc_get_order( $order_id );
$order_items    = $order->get_items();

// Reset shipping first
WC()->shipping()->reset_shipping();

// Set correct temporary location
if ( $country != '' ) {
WC()->customer->set_billing_location( $country, $state, $postcode, $city );
WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
} else {
WC()->customer->set_billing_address_to_base();
WC()->customer->set_shipping_address_to_base();
}

// Remove all current items from cart
if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
WC()->cart->empty_cart();
}

// Add all items to cart
foreach ($order_items as $order_item) {
WC()->cart->add_to_cart($order_item['product_id'], $order_item['qty']);
}

// Calculate shipping
$packages = WC()->cart->get_shipping_packages();
$shipping = WC()->shipping->calculate_shipping($packages);
$available_methods = WC()->shipping->get_packages();

请使用所需的行为、特定问题和代码更新您的问题。看:我已经更新了帖子。我认为期望的行为是明确的。我不确定实现这一点的确切代码。