Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nahlen

    (@nahlen)

    Thanks for your help!

    Thread Starter nahlen

    (@nahlen)

    It was my mistake. I used a PHP code to get the “order again” to appear at the “orders” page. This caused the problem. When I deactivated the code everything works fine.

    Do you know a way to show the “order again” on the “orders” page that works?

    Is used this code:

    // Modify “Order Again” button to add products to cart
    add_action(‘woocommerce_my_account_my_orders_actions’, ‘custom_order_again_redirect’, 10, 2);

    function custom_order_again_redirect($actions, $order) {
    if ($order->has_status(‘completed’) || $order->has_status(‘processing’) || $order->has_status(‘on-hold’) || $order->has_status(‘cancelled’) || $order->has_status(‘levererad’) || $order->has_status(‘refunded’)) {
    $actions[‘order-again’] = array(
    ‘url’ => wp_nonce_url(add_query_arg(‘order_again’, $order->get_id(), wc_get_cart_url()), ‘woocommerce-order-again’),
    ‘name’ => __(‘Beställ mer’, ‘woocommerce’),
    );
    }
    return $actions;
    }

    // Handle the order again action
    add_action(‘template_redirect’, ‘handle_order_again_action’);

    function handle_order_again_action() {
    if (isset($_GET[‘order_again’]) && !empty($_GET[‘order_again’])) {
    $order_id = absint($_GET[‘order_again’]);
    $order = wc_get_order($order_id);

        if ($order) {
            foreach ($order->get_items() as $item_id => $item) {
                $product_id = $item->get_product_id();
                $quantity = $item->get_quantity();
                WC()->cart->add_to_cart($product_id, $quantity);
            }
            wp_redirect(wc_get_cart_url());
            exit;
        }
    }

    }

Viewing 2 replies - 1 through 2 (of 2 total)