wordpress - 在 Woocommerce 3 中自定义购物车项目删除通知
问题描述
我正在使用 WooCommerce 3.4.4 版本,当您按“X”按钮从购物车页面中删除产品时,我正在尝试编辑通知消息。
目前通知是"<product name>" removed. Undo?
我想删除引号并将消息更改为Product name has been removed. [Undo button]
我已经设法通过写作删除了产品名称中的引号
add_filter( 'woocommerce_cart_item_removed_title', 'removed_from_cart', 10, 2);
function removed_from_cart( $message, $product_data ) {
$product = get_the_title($product_data['product_id']);
$message = $product;
return $message;
}
但是我对如何进行其余的编辑有点困惑。任何帮助表示赞赏。
解决方案
更新
唯一可用的钩子是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;
}
这是您将得到的:
推荐阅读
- c# - .NET CORE 2.1 JWT Bearer Authorization 未按请求调用 - 始终返回 200 OK
- installation - 作为顾问远程交付软件
- javascript - Nativescript 保持键盘在 Enter 按下后显示 - Android
- c# - List的数组,获取每个列表的相同字符,如何?
- julia - Julia:我怎样才能使这个重复的条件语句代码更短?
- javascript - TradingView 没有在 Vue 挂载的钩子中定义
- angularjs - 错误:未定义不是对象(评估'$scope.$storage.match_id')
- python - 无法将 pyexcel-xls 与 pyinstaller python 3.6 版一起使用
- optimization - 声纳报告中的认知复杂性是什么?
- java - Android:在fragment类中,通过getter方法访问Activity类的变量,变量的值保持为0