WC_REST_Paypal_Standard_Controller::rebuild_cart_from_order
Rebuild the session cart.
Метод класса: WC_REST_Paypal_Standard_Controller{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->rebuild_cart_from_order( $order );
- $order(WC_Order) (обязательный)
- The order object.
Код WC_REST_Paypal_Standard_Controller::rebuild_cart_from_order() WC REST Paypal Standard Controller::rebuild cart from order WC 11.2.1
private function rebuild_cart_from_order( $order ) {
wc_load_cart();
WC()->cart->empty_cart();
foreach ( $order->get_items() as $item ) {
$product_id = $item->get_product_id();
$product = $item->get_product();
if ( ! $product ) {
continue;
}
if ( $product->is_type( 'variation' ) ) {
$variation_id = $item->get_variation_id();
WC()->cart->add_to_cart( $product_id, $item->get_quantity(), $variation_id );
continue;
}
WC()->cart->add_to_cart( $product_id, $item->get_quantity() );
}
// Re-apply coupons present on the order so discounts/totals are accurate.
if ( method_exists( $order, 'get_coupon_codes' ) ) {
foreach ( (array) $order->get_coupon_codes() as $code ) {
if ( $code ) {
WC()->cart->apply_coupon( $code );
}
}
}
// Re-apply shipping methods present on the order so totals are accurate.
$order_shipping_rate_id = $this->get_order_shipping_rate_id( $order );
if ( ! empty( $order_shipping_rate_id ) ) {
WC()->session->set( 'chosen_shipping_methods', array( $order_shipping_rate_id ) );
}
}