Ad

Woocommerce How To Add Title Attribute To Anchor Tag For Product Name On Mini Cart

I want to add a title attribute to the anchor tag for the product names in the Woocommerce mini cart, so that when a customer hovers over the product name, a toolbox will appear with the product name.

<a href="" title=""></a>

Is there a function to achieve this?

Ad

Answer

Copy the file found at

wp-content/plugins/woocommerce/templates/cart/mini-cart.php -> wp-content/themes/your-theme/woocommerce/cart/mini-cart.php

into your store’s child theme .

Note that if you customize the parent theme rather than the child theme, any changes will be overwritten with theme updates.

Change code in wp-content/themes/your-theme/woocommerce/cart/mini-cart.php

Before

<a href="<?php echo esc_url( $product_permalink ); ?>">
                            <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>

After

<a href="<?php echo esc_url( $product_permalink ); ?>" title="<?php echo esc_attr($product_name); ?>">
                            <?php echo $thumbnail . wp_kses_post( $product_name ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</a>

Fоr tooltip you can use 'jquery-ui'. Add below code to functions.php of your theme

function my_scripts_method() {
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-ui-core');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');

You need to add this code to your theme in js file

jQuery( function() {
    jQuery( '.woocommerce-mini-cart-item a').tooltip();
} );
Ad
source: stackoverflow.com
Ad