[英]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.