• best_wish

    (@best_wish)


    Hi everyone,

    I would like to know how to apply the Order Again option for Variable product correctly. The issue is that whenever customer(on My account page>>view a specific order with Variable product) use the “Order Again” option for the order of Variable product that was purchased before, the order made with “Order Again” option just shows the product name or sku on shopping cart, email order confirmation, order page on dashboard, without considering if there are info from variable option info on that variable product’s page…that makes unclear. Could it be exactly like the order purchased for first time to show the variable option info?

    below is about that Option on the file as class-wc-form-handler

    Pls help and appreciate anyone who could help…Thank you every much

    /**
    * 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, $product_id ) ) {
    $variations[ $meta_name ] = $meta_value[0];
    }
    }

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin-Woocommerce] "Order Again" option for Variable product’ is closed to new replies.