更新
唯一可用的钩子是您已经在使用的woocommerce_cart_item_removed_title。并在引号之间显示产品名称。您还可以使用gettex 过滤器挂钩来删除“撤消”文本后的?:
add_filter( 'woocommerce_cart_item_removed_title', 'removed_from_cart_title', 12, 2);
function removed_from_cart_title( $message, $cart_item ) {
$product = wc_get_product( $cart_item['product_id'] );
if( $product )
$message = sprintf( __('Product %s has been'), $product->get_name() );
return $message;
}
add_filter('gettext', 'cart_undo_translation', 35, 3 );
function cart_undo_translation( $translation, $text, $domain ) {
if( $text === 'Undo?' ) {
$translation = __( 'Undo', $domain );
}
return $translation;
}
代码进入您的活动子主题(或活动主题)的 function.php 文件中。经过测试并且可以工作。
但是你不能改变或添加button标签类<a>html标签……
改为使用现有的restore-item标签类为其添加一些自定义 CSS 样式。
下面是一些 CSS 样式示例,您可以将其添加到活动子主题的 styles.css 文件中:
.woocommerce-message .restore-item, {
float: right;
padding: 0 0 0 1em;
background: 0 0;
color: #fff;
box-shadow: none;
line-height: 1.618;
border-width: 0 0 0 1px;
border-left-style: solid;
border-left-color: rgba(255,255,255,.25)!important;
border-radius: 0;
}
.woocommerce-message .restore-item:hover {
background: 0 0;
color: #fff;
opacity: .8;
}
这是你将得到的: