Skip to content

Instantly share code, notes, and snippets.

@PluginHive
Created January 20, 2020 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PluginHive/3e002b7b36d1545ca1af2334f1ddbb1e to your computer and use it in GitHub Desktop.
Save PluginHive/3e002b7b36d1545ca1af2334f1ddbb1e to your computer and use it in GitHub Desktop.
Customize message which is displaying after add to cart a booking product
add_filter( 'wc_add_to_cart_message_html', 'phive_added_to_cart_message', 11,2 );
function phive_added_to_cart_message( $message, $products ){
$added_to_cart_message='Booking Done. Please check cart for payment.'; //make your changes
$is_booking_product = false;
foreach ($products as $product_id => $quantity) {
if( ph_is_bookable_product($product_id) ){
$is_booking_product = true;
break;
}
}
if( $is_booking_product )
{
//if directly redirected to cart, continue booking message should come instead of view cart.
if ( 'yes' === get_option( 'woocommerce_cart_redirect_after_add' ) )
{
$added_text = __('Booking Done.','bookings-and-appointments-for-woocommerce');
$return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) );
$message = sprintf( '<a href="%s" tabindex="1" class="button wc-forward">%s</a>%s', esc_url( $return_to ), esc_html__( 'Continue booking', 'bookings-and-appointments-for-woocommerce' ), esc_html( $added_text ) );
}
else
{
$message = '<a href="'.wc_get_page_permalink( 'cart' ).'" class="button wc-forward">'.__('View cart','bookings-and-appointments-for-woocommerce').'</a> '.__($added_to_cart_message,'bookings-and-appointments-for-woocommerce');
}
$message = apply_filters( 'ph_booking_add_to_cart_message_html', $message, $products );
}
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment