• Resolved magapascansky

    (@magapascansky)


    Hello! I am developing my own WooCommerce theme for my site and I’m having trouble with the thank you / order received page. Whenever I purchase something it redirects me to my homepage (that I understand is because I have no thank you page) with this url https://localhost:8888/dacre/finalizar-comprar/order-received/112/?key=wc_order_TmuIT5610SQvm

    I tried creating a thankyou.php under mytheme/woocommerce/checkout but it doesn’t work.

    Can you help me with these? I want to custom my thank you page including all the details from the purchase.

    Thank you in advance!

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • isodos

    (@isodos)

    Sometimes, redirection issues can be caused by permalink settings. Go to WordPress Admin > Settings > Permalinks and simply click “Save Changes” without making any changes. This action flushes the permalink structure and can resolve routing issues.

    If that doesn’t work, make sure that the thank you page php is structured correctly:

    <?php
    defined( 'ABSPATH' ) || exit;
    
    global $wp;
    
    // Check if the order exists.
    if ( isset( $wp->query_vars['order-received'] ) ) {
        $order_id = absint( $wp->query_vars['order-received'] );
    } else {
        $order_id = 0;
    }
    
    $order = wc_get_order( $order_id );
    
    if ( $order && $order->has_status( 'completed' ) ) {
        // Your customizations here. For example:
        echo '<p>Thank you. Your order has been received.</p>';
    
        // Display order details.
        echo '<ul>';
        echo '<li>Order number: ' . $order->get_order_number() . '</li>';
        echo '<li>Date: ' . wc_format_datetime( $order->get_date_created() ) . '</li>';
        echo '<li>Email: ' . $order->get_billing_email() . '</li>';
        echo '<li>Total: ' . $order->get_formatted_order_total() . '</li>';
        echo '<li>Payment method: ' . $order->get_payment_method_title() . '</li>';
        echo '</ul>';
    
        // Display additional information - e.g., customer details, products ordered.
        // This part is highly customizable depending on what details you want to show.
    
    } else {
        // If order not found or not completed.
        echo '<p>Order not found or has not been completed.</p>';
    }
    
    Thread Starter magapascansky

    (@magapascansky)

    Hello and thanks for your quick response! I tried saving changes in permalink and also copying your code in my thankyou.php that is located under mytheme/woocommerce/checkout but neither worked ??

    anastas10s

    (@anastas10s)

    ?? hey @magapascansky

    Thanks for reaching out to Woo Support!

    Hello! I am developing my own WooCommerce theme for my site and I’m having trouble with the thank you / order received page.

    From what I gather, you’d need a hand with template overriding via a theme.

    Luckily, there’s documentation on that, which can be found linked directly here, for your convenience.

    I hope this is helpful! Please let us know if you have any further questions or concerns.
    We will be happy to help you further.

    • This reply was modified 1 year ago by anastas10s. Reason: typo
    Thread Starter magapascansky

    (@magapascansky)

    Hello! That is what I tried but my theme isn’t even redirecting to the original template. It just goes to my index.php with the url https://localhost:8888/dacre/finalizar-comprar/order-received/119/?key=wc_order_FsNx6ZpbfAO4d.

    Thread Starter magapascansky

    (@magapascansky)

    I also tried with this code in my functions.php but it didn’t work either.

    function wc_custom_thank_you_page( $order_id ) {

    $order = wc_get_order( $order_id );

    wp_redirect( ‘https://localhost:8888/dacre/thank-you/&#8217; );

    }

    add_action( ‘woocommerce_thankyou’, ‘wc_custom_thank_you_page’ );

    ?>

    Thread Starter magapascansky

    (@magapascansky)

    Update: this code worked but I want to send the purchase id as a parameter.

    add_action( ‘template_redirect’, ‘woo_custom_redirect_after_purchase’ );

    function woo_custom_redirect_after_purchase() {

    global $wp;

    if ( is_checkout() && !empty( $wp->query_vars[‘order-received’] ) ) {

    wp_redirect(home_url() . “/thank-you”);

    exit;

    }

    }

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @magapascansky,

    To send the purchase ID as a parameter, you need to modify the redirection URL in your function. You can access the order ID with $wp->query_vars['order-received'] and append it to the URL as a parameter.

    For reference, these particular forums are meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question.

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Woocommerce order received page’ is closed to new replies.