Like in cart, how could i do to be able to remove product in Checkout page with a 'x' link ?
Is there any hook do to that ?
thanks
Join Stack Overflow to learn, share knowledge, and build your career.
Like in cart, how could i do to be able to remove product in Checkout page with a 'x' link ?
Is there any hook do to that ?
thanks
I was confronted to the same problem, and couldn't find a way to solve it on Google. So i tried by myself and found this solution :
Overriding woocommerce order review on checkout page in your theme :
Adding the remove x button for each product on the checkout page :
On the new review-order.php (yourtheme/woocommerce/checkout) :
Add <th class="product-remove"><?php _e( 'Remove', 'woocommerce' ); ?></th>
in the head of the shop table.
Copy from the default cart.php file (l. 49) (plugins/woocommerce/templates/cart)
<td class="product-remove">
<?php
echo 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_get_cart_remove_url( $cart_item_key ) ),
esc_html__( 'Remove this item', 'woocommerce' ),
esc_attr( $_product->get_id() ),
esc_attr( $_product->get_sku() )
),
$cart_item_key
);
?>
</td>
I hope this will be helpful as it is my first answer on StackOF, It has done the job for me, but it may not be the best way to proceed.
Looking forward to new answers ;)
The function function ns_woocommerce_checkout_remove_item hooks into woocommerce_cart_item_name filter, which allows to change the output and add a link (the cross icon) around the product item name. The link we add is based on WC()->cart->get_remove_url( $cart_item_key ) function, which creates an url for specified cart item key.
Add the code below to your theme’s functions.php file.
function ns_woocommerce_checkout_remove_item( $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', 'ns_woocommerce_checkout_remove_item', 10, 3 );