It would seem that the logic of WooCommerce is transparent and clear: adding products on the product page, deleting products on the cart page (Cart), and the checkout page is needed to enter customer data. However, this logic does not suit everyone. Some people want to know how to remove products on the checkout page

On one of the clients’ sites, a simplified order creation scheme was introduced, in which the buyer, after clicking the “Buy” button, is immediately redirected to the checkout page. As you can imagine, the “Cart” page does not participate in this scheme and is generally hidden.

The problem is that some customers can add several products to the cart (and several times) and then, having gone to the checkout page, they no longer have the opportunity to change their order, and therefore refuse to purchase.

It is clear that the best solution is to return the cart to the site. But there is also a compromise: add buttons to delete items on the checkout page. To do this, copy and paste the following code into the functions.php file of the active site theme:

/* Speedplus.com.ua ## Allows to remove products in checkout page */
function speedplus_checkout_remove_product( $product_name, $cart_item, $cart_item_key ) {
	if ( is_checkout() ) {
		$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
		$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
		$remove_link = apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
			'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>',
			esc_url( WC()->cart->get_remove_url( $cart_item_key ) ),
			__( 'Remove this item', 'woocommerce' ),
			esc_attr( $product_id ),
			esc_attr( $_product->get_sku() )
        ), $cart_item_key );
		return '<span>' . $remove_link . '</span> <span>' . $product_name . '</span>';
	}
	return $product_name;
}
add_filter( 'woocommerce_cart_item_name', 'speedplus_checkout_remove_product', 10, 3 );

Leave a comment

Your email address will not be published.