PHP Snippet: Show Add-Ons Area @ WooCommerce Checkout Page
Requirements:
- Product IDs you want to add to Cart (14877, 14879, 15493 in my example)
- No “redirect to Cart after add to cart” option checked in WooCommerce settings
/** * @snippet Upsell Area - WooCommerce Checkout * @how-to Get CustomizeWoo.com FREE * @author Rodolfo Melogli * @compatible WooCommerce 3.6.1 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ add_action( 'woocommerce_review_order_before_submit' , 'bbloomer_checkout_add_on' , 9999 ); function bbloomer_checkout_add_on() { $product_ids = array ( 14877, 14879, 15493 ); $in_cart = false; foreach ( WC()->cart->get_cart() as $cart_item ) { $product_in_cart = $cart_item [ 'product_id' ]; if ( in_array( $product_in_cart , $product_ids ) ) { $in_cart = true; break ; } } if ( ! $in_cart ) { echo '<h4>Make a Donation?</h4>' ; echo '<p><a class="button" style="margin-right: 1em; width: auto" href="?add-to-cart=14877"> €5 </a><a class="button" style="margin-right: 1em; width: auto" href="?add-to-cart=14879"> €20 </a><a class="button" style="width: auto" href="?add-to-cart=15493"> €50 </a></p>' ; } } |
No comments:
Post a Comment