Standaard kun je in de WooCommerce checkout geen product verwijderen. Dit kan alleen in de winkelmand.
Door het toevoegen van de onderstaande code in je functions.php van je child-theme of in bijvoorbeeld de Code Snippets plugin wordt deze mogelijkheid alsnog toegevoegd.
Producten verwijderen uit checkout met code
/*
* It will add Delete button, Quanitity field on the checkout page Your Order Table.
*/
function webroom_add_delete_and_quantity_on_checkout( $product_title, $cart_item, $cart_item_key ) {
/* Checkout page check */
if ( is_checkout() ) {
/* Get Cart of the user */
$cart = WC()->cart->get_cart();
foreach ( $cart as $cart_key => $cart_value ){
if ( $cart_key == $cart_item_key ){
$product_id = $cart_item['product_id'];
$_product = $cart_item['data'] ;
/* Step 1 : Add delete icon */
$return_value = sprintf(
'<a href="%s" class="remove" title="%s" data-product_id="%s" data-product_sku="%s">×</a>',
esc_url( wc_get_cart_remove_url( $cart_key ) ),
__( 'Delete', 'woocommerce' ),
esc_attr( $product_id ),
esc_attr( $_product->get_sku() )
);
/* Step 2 : Add product name */
$return_value .= ' <span class = "product_name" >' . $product_title . '</span>' ;
/* Step 3 : Add quantity selector */
if ( $_product->is_sold_individually() ) {
$return_value .= sprintf( ' <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_key );
} else {
$return_value .= woocommerce_quantity_input( array(
'input_name' => "cart[{$cart_key}][qty]",
'input_value' => $cart_item['quantity'],
'max_value' => $_product->backorders_allowed() ? '' : $_product->get_stock_quantity(),
'min_value' => '1'
), $_product, false );
}
return $return_value;
}
}
}else{
/*
* It will return the product name on the cart page.
* As the filter used on checkout and cart are same.
*/
$_product = $cart_item['data'] ;
$product_permalink = $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '';
if ( ! $product_permalink ) {
$return_value = $_product->get_title() . ' ';
} else {
$return_value = sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_title());
}
return $return_value;
}
}
add_filter ('woocommerce_cart_item_name', 'webroom_add_delete_and_quantity_on_checkout' , 10, 3 );