简体   繁体   English

向 Woocommerce 购物车项目添加溢出和标题标签

[英]Add overflow and title tag to Woocommerce cart item

I need to add我需要添加

overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

as well as a title tag with the product name (a title="") to the Woocommerce product names in the cart table on the cart page.以及带有产品名称 (a title="") 的标题标签到购物车页面上购物车表格中的 Woocommerce 产品名称。 If I add the css to如果我将 css 添加到

.product-name a

it will not wokr and the product thumbnail is not displayed any longer.它不会工作,并且不再显示产品缩略图。 How can I add the css as well as adding the title tag to the links?如何添加 css 以及将标题标签添加到链接?

That CSS, which you probably took from my " WooCommerce: How to Shorten Product Titles " tutorial, won't work on the Cart page as you're inside a table.您可能从我的“ WooCommerce:如何缩短产品标题”教程中获取的那个 CSS 将无法在购物车页面上使用,因为您在表格中。 It would simply expand the table column to the length of the item name, which is not ideal.它只会将表格列扩展到项目名称的长度,这并不理想。

In this case you need PHP, and by using the same reference, you could test the following customization:在这种情况下,您需要 PHP,并且通过使用相同的参考,您可以测试以下自定义:

add_filter( 'woocommerce_cart_item_name', 'bbloomer_shorten_cart_item_title', 9999, 3 );
 
function bbloomer_shorten_cart_item_title( $name, $cart_item, $cart_item_key ) {
    
    // GET PRODUCT
    $_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
    
    // GET PERMALINK
    $product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
    
    // ADD TITLE, LIMIT TO 15 CHARS AND ADD ELLIPSIS
    return sprintf( '<a href="%s" title="%s">%s</a>', esc_url( $product_permalink ), $_product->get_name(), substr( $_product->get_name(), 0, 15 ) . '...' );
    
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在图像中添加产品永久链接标记woocommerce购物车项目? - How can add product permalink in image a tag woocommerce cart item? 更改 WooCommerce 添加到特定标签的购物车文本 - Change WooCommerce add to cart text for specific tag 在 Woocommerce 中添加到购物车操作时,将自定义选择的日期添加到购物车项目 - Add a custom chosen date to cart item on add to cart action in Woocommerce WooCommerce:将输入添加到购物车,然后将数据添加到购物车项目 - WooCommerce: Add input to cart and then add the data to cart item 在WooCommerce中,购物车商品标题未连接到HTML表中 - Cart item title isn't concatenated into an HTML table in WooCommerce 在 WooCommerce 中隐藏购物车项目标题的变化信息 3+ - Hide variation info from cart item title in WooCommerce 3+ 用管道替换 WooCommerce 购物车项目变体标题中的某个字符 - Replace a certain character in WooCommerce cart item variations title by a pipe 在 Woocommerce 购物车页面中的购物车项目名称后添加产品 ID - Add the product ID after the cart item name in Woocommerce cart page 根据 WooCommerce 购物车总数添加或删除特定购物车项目 - Add or remove specific cart Item based on WooCommerce cart total 通过 URL 添加到购物车上的 WooCommerce 自定义购物车商品价格 - WooCommerce custom cart item price on add-to cart via the URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM