I
I
Ivseti2021-10-13 21:37:38
WordPress
Ivseti, 2021-10-13 21:37:38

How to correctly display product removal as an icon in Woocommerce?

The situation is this. On the PC, I just have a link "Delete product", on the phone there is a cross icon. Everything is done, everything works. But since the main output is hidden on PC via css:

<?php
                echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                  'woocommerce_cart_item_remove_link',
                  sprintf(
                    '<a class="h-text-mob" href="%s" id="remove-from-cart" aria-label="%s" data-product_id="%s" data-product_sku="%s">%s</a>',
                    esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
                    esc_html__( 'Убрать из корзины', 'woocommerce' ),
                    esc_attr( $product_id ),
                    esc_attr( $_product->get_sku() ),
                    esc_html__( 'Убрать из корзины', 'woocommerce' )

                  ),
                  $cart_item_key
                );
              ?>


And for the phone, a jailbreak is pushed:
if ($(window).width() < 767) {
    jQuery('.push-name').after(' <?php echo apply_filters( 
                  'woocommerce_cart_item_remove_link',
                  sprintf(
                    '<a class="h-text-mob" href="%s" id="remove-from-cart" aria-label="%s" data-product_id="%s" data-product_sku="%s"><i class="far fa-times-circle"></i></a>',
                    esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
                    esc_html__( 'Убрать из корзины', 'woocommerce' ),
                    esc_attr( $product_id ),
                    esc_attr( $_product->get_sku() ),
                    esc_html__( 'Убрать из корзины', 'woocommerce' )

                  ),
                  $cart_item_key
                );
              ?>');


It turns out that php puts the correct link and css hides it, and the jekver pushes the link for the bottom product. As a result, it turns out that if there are two goods in the basket, then when the first is deleted, the second is deleted. What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivseti, 2021-10-14
@Ivseti

I figured it out, removed the jekveri, and displayed this button using the html skeleton (I just copied php), hid the css text on the mobile. Issue resolved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question