WooCommerce – Losing add-ons/variations when Ordering Again
-
I really need help with WooCommerce! The products in the store have add-on options a customer can add. The ordering process goes fine but if a customer wants to reorder, WooCommerce isn’t adding the variations/add-ons to the new order. I’ve looked at the code and it plainly says “Load all product info including variation data” and the update said there was a fix applied but it still doesn’t work.
This is the code I am looking at for the “Order Again” section:
* Place a previous order again. */ public static function order_again() { // Nothing to do if ( ! isset( $_GET['order_again'] ) || ! is_user_logged_in() || ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], 'woocommerce-order_again' ) ) { return; } // Clear current cart WC()->cart->empty_cart(); // Load the previous order - Stop if the order does not exist $order = wc_get_order( absint( $_GET['order_again'] ) ); if ( empty( $order->id ) ) { return; } if ( ! $order->has_status( 'completed' ) ) { return; } // Make sure the user is allowed to order again. By default it check if the // previous order belonged to the current user. if ( ! current_user_can( 'order_again', $order->id ) ) { return; } // Copy products from the order to the cart foreach ( $order->get_items() as $item ) { // Load all product info including variation data $product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $item['product_id'] ); $quantity = (int) $item['qty']; $variation_id = (int) $item['variation_id']; $variations = array(); $cart_item_data = apply_filters( 'woocommerce_order_again_cart_item_data', array(), $item, $order ); foreach ( $item['item_meta'] as $meta_name => $meta_value ) { if ( taxonomy_is_product_attribute( $meta_name ) ) { $variations[ $meta_name ] = $meta_value[0]; } elseif ( meta_is_product_attribute( $meta_name, $meta_value[0], $product_id ) ) { $variations[ $meta_name ] = $meta_value[0]; } } // Add to cart validation if ( ! apply_filters( 'woocommerce_add_to_cart_validation', true, $product_id, $quantity, $variation_id, $variations, $cart_item_data ) ) { continue; } WC()->cart->add_to_cart( $product_id, $quantity, $variation_id, $variations, $cart_item_data ); } do_action( 'woocommerce_ordered_again', $order->id ); // Redirect to cart wc_add_notice( __( 'The cart has been filled with the items from your previous order.', 'woocommerce' ) ); wp_safe_redirect( WC()->cart->get_cart_url() ); exit; }
Any help or direction is greatly appreciation!
- The topic ‘WooCommerce – Losing add-ons/variations when Ordering Again’ is closed to new replies.