John Davidson

wordpress - Alert after checkout with woocommerce from function.php

0 comments
Message:


I'm using woocommerce to take appointement, I know it kind a weird but it's perfect for this project.


After the checkout, I redirect the user to the home page and I want to display an alert or a bar to say "Message send successfully"


How can I manage that from function.php ?


Code from my function.php :


function woocommerce_redirect_after_checkout() {
global $wp;

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

global $woocommerce;

$woocommerce->cart->empty_cart();

wp_redirect(get_home_url() );

//HERE echo '<script>alert('bla')</script>';

exit;
}

}

Thx



My Answer:
"Thank you for your appointment! We will contact you shortly to confirm."

You can achieve this by adding the following code to your theme's functions.php file:

php
add_action( 'woocommerce_thankyou', 'display_appointment_confirmation', 10, 1 );
function display_appointment_confirmation( $order_id ) {
$order = wc_get_order( $order_id );
$items = $order->get_items();

// Check if the order contains appointment products
$is_appointment = false;
foreach ( $items as $item ) {
if ( $item->get_product()->is_type( 'appointment' ) ) {
$is_appointment = true;
break;
}
}

// Display confirmation message if the order contains appointment products
if ( $is_appointment ) {
echo '
Thank you for your appointment! We will contact you shortly to confirm.
';
}
}


This code will display the confirmation message after the checkout if the order contains appointment products. You can customize the message and styling as needed.

Rate this post

4 of 5 based on 8811 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us