Do you want to be able to upsell products on the WooCommerce checkout without any bloated, expensive plugins? This quick guide shows you how to upsell a product at the checkout stage of the buying journey by implementing a checkbox which adds a product of your choice to the order. Simple replace the product ID in the code with your product ID of choice and change the text as necessary. We recommend making the upsell product a hidden, discounted product so that the upsell offer is more appealing and true in that it is a one-time offer only.
/**
* Snippet Name: Add custom hidden_product_upsell at WooCommerce checkout
* Snippet Author: ecommercehints.com
*/
add_action( 'woocommerce_review_order_before_submit', 'ecommercehints_hidden_product_upsell_checkbox' );
add_action( 'woocommerce_checkout_order_processed', 'ecommercehints_hidden_product_upsell_something', 9, 3 );
function ecommercehints_hidden_product_upsell_checkbox() {
echo '
';
}
function ecommercehints_hidden_product_upsell_something( $order_id, $posted_data, $order ) {
if( isset( $_REQUEST['ecommercehints_hidden_product_upsell'] ) && $_REQUEST['ecommercehints_hidden_product_upsell'] == 'on' ) {
$product = wc_get_product( 15 ); // The product ID you would like to upsell
$order->add_product( $product );
$order->calculate_totals();
}
}