skip to Main Content

Is it possible to move the “remove product” link from the first <td> in the cart under the quantity selector? And delete the first <td> with it?

I found the funvtion in the template cart/cart.php.
Unfortunately I couldn’t find any hooks to change the position or delete the <td>.

Is there really no way to change that without touching/copy the template file?

This ist the <td> with the quantity field:

<td class="product-name" data-title="<?php esc_attr_e( 'Product', 'woocommerce' ); ?>">
<?php
if ( ! $product_permalink ) {
    echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key ) . '&nbsp;' );
} else {
    echo wp_kses_post( apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name() ), $cart_item, $cart_item_key ) );
}

do_action( 'woocommerce_after_cart_item_name', $cart_item, $cart_item_key );

// Meta data.
echo wc_get_formatted_cart_item_data( $cart_item ); // PHPCS: XSS ok.

// Backorder notification.
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) ) {
    echo wp_kses_post( apply_filters( 'woocommerce_cart_item_backorder_notification', '<p class="backorder_notification">' . esc_html__( 'Available on backorder', 'woocommerce' ) . '</p>', $product_id ) );
}
?>
</td>

I don’t want to touch the template because it’s the only detail that I want to change and couldn’t do at the moment. And for that “little” detail I don’t want to chage such a big and crucial template file. I don’t have to worry about future updates an newer versions of the file.

2

Answers


  1. you can use jquery to do that

    here it is

    jQuery(document).ready(function(){
       jQuery(".remove").appendTo(".quantity");
    });
    
    Login or Signup to reply.
  2. Please paste the below code in your current theme functions.php file.

    add_filter('woocommerce_cart_item_remove_link','remove_cart_icon',10,2);
        function remove_cart_icon($plink,$link){
            return '';
        }
    
    add_filter('woocommerce_cart_item_quantity','change_cart_remove_link',10,3);
    function change_cart_remove_link($product_quantity, $cart_item_key, $cart_item){
    
        //create new product object
        $_product = new WC_Product($cart_item['product_id']);//product_id
    
        $cart_remove_link = sprintf(
                                        '<a href="%s" class="remove button button_js" aria-label="%s" data-product_id="%s" data-product_sku="%s"><span class="button_icon">&times;</span></a>',
                                        esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
                                        __( 'Remove this item', 'woocommerce' ),
                                        esc_attr( $_product->get_id() ),
                                        esc_attr( $_product->get_sku() )
                                    );
    
        $product_quantity .= $cart_remove_link; 
        return $product_quantity;
    }
    

    I hope it will help you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search