Add a delete product button to product page notice message.
-
Hi,
I want to replicate the remove product functionality you get in the cart within the success.php message that appears whenever you add a product to your cart on the single product page. I want it to sit as a button next to the view cart button.
I have managed to get achieve this by using the following:
<?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $_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 ); if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_cart_item_visible', true, $cart_item, $cart_item_key ) ) { $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key ); ?> <div class="woocommerce-cart-form__cart-item <?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>"> <?php echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" class="remove blueB removeProd" aria-label="%s" data- product_id="%s" data-product_sku="%s">Remove product</a>', esc_url( wc_get_cart_remove_url( $cart_item_key ) ), esc_html__( 'Remove this item', 'woocommerce' ), esc_attr( $product_id ), esc_attr( $_product->get_sku() ) ), $cart_item_key); ?> </div> <?php }}?>
I know you need to pull the product ID and key for this to work, however it appears to work at first, but then it starts to include multiple buttons for different items within the cart.
Is it possible to just have the button to appear for that one product you add to cart on the single product page? Not display previous products added to the cart?
The page I need help with: [log in to see the link]
- The topic ‘Add a delete product button to product page notice message.’ is closed to new replies.