use*_*606 3 wordpress product cart notice woocommerce
我正在使用 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;
}
Run Code Online (Sandbox Code Playgroud)
但我对如何进行其余的编辑有点困惑。任何帮助表示赞赏。
更新
\n唯一可用的钩子是woocommerce_cart_item_removed_title您已经使用的。并在引号之间显示产品名称。您还可以使用gettex过滤器挂钩删除?“撤消”文本后的内容:
add_filter( \'woocommerce_cart_item_removed_title\', \'removed_from_cart_title\', 12, 2);\nfunction removed_from_cart_title( $message, $cart_item ) {\n $product = wc_get_product( $cart_item[\'product_id\'] );\n\n if( $product )\n $message = sprintf( __(\'Product %s has been\'), $product->get_name() );\n\n return $message;\n}\n\nadd_filter(\'gettext\', \'cart_undo_translation\', 35, 3 );\nfunction cart_undo_translation( $translation, $text, $domain ) {\n\n if( $text === \'Undo?\' ) {\n $translation = __( \'Undo\', $domain );\n }\n return $translation;\n}\nRun Code Online (Sandbox Code Playgroud)\n代码位于活动子主题(或活动主题)的 function.php 文件中。经过测试并有效。
\n\n\n但您不能更改或添加
\nbutton<a>html tag\xe2\x80\xa6
\n的标签类,而是使用现有restore-item标签类向其添加一些自定义 CSS 样式。
下面是一些 CSS 样式示例,您可以将其添加到styles.css活动子主题的文件中:
add_filter( \'woocommerce_cart_item_removed_title\', \'removed_from_cart_title\', 12, 2);\nfunction removed_from_cart_title( $message, $cart_item ) {\n $product = wc_get_product( $cart_item[\'product_id\'] );\n\n if( $product )\n $message = sprintf( __(\'Product %s has been\'), $product->get_name() );\n\n return $message;\n}\n\nadd_filter(\'gettext\', \'cart_undo_translation\', 35, 3 );\nfunction cart_undo_translation( $translation, $text, $domain ) {\n\n if( $text === \'Undo?\' ) {\n $translation = __( \'Undo\', $domain );\n }\n return $translation;\n}\nRun Code Online (Sandbox Code Playgroud)\n这就是您将得到的:
\n\n| 归档时间: |
|
| 查看次数: |
5363 次 |
| 最近记录: |