php – WooCommerce:购物车价格覆盖文字
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – WooCommerce:购物车价格覆盖文字,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2341字,纯文字阅读大概需要4分钟。
内容图文
我们有一堆产品:
>没有价格
>零价格
我们使用内置挂钩购买它们但购物车在结账时仍然显示为0.
我们喜欢购物车和购物车.结帐摘要显示“特殊订单”或任何其他文本,但似乎WooCommerce使基于文本的价格无效.
试过这个:
WooCommerce: Add product to cart with price override?
以上工作正常,数字覆盖,但尝试使用文本覆盖时,它默认返回显示0价格.
为什么?这些产品是按订单生产的,商店管理员将在与客户/供应商交谈后更新价格.
解决方法:
您需要过滤显示购物车中的价格和小计的字符串.您提到的链接讨论了更改实际价格.在您的情况下,价格是0美元,直到您稍后设置实际价格.也可能是购物车总数的过滤器,但这应该是一个开始:
add_filter( 'woocommerce_cart_item_price', 'so_38057349_cart_item_price', 10, 3 );
function so_38057349_cart_item_price( $price, $cart_item, $cart_item_key ) {
if ( $cart_item[ 'data' ]->price == 0 ) {
$price = __( 'Special Order', 'yourtheme' );
}
return $price;
}
add_filter( 'woocommerce_cart_item_subtotal', 'so_38057349_cart_item_subtotal', 10, 3 );
function so_38057349_cart_item_subtotal( $subtotal, $cart_item, $cart_item_key ) {
if ( $cart_item[ 'data' ]->price == 0 ) {
$subtotal = __( 'To be determined', 'yourtheme' );
}
return $subtotal;
}
add_filter( 'woocommerce_order_formatted_line_subtotal', 'so_38057349_order_item_subtotal', 10, 3 );
function so_38057349_order_item_subtotal( $subtotal, $item, $order ) {
if ( isset( $item[ 'line_subtotal' ] ) && $item[ 'line_subtotal' ] == 0 ) {
$subtotal = __( 'To be determined', 'yourtheme' );
}
return $subtotal;
}
当然,这也适用于价格为0的任何产品,也可能不仅适用于您自定义构建的产品,因此您可能需要比我在此处提供的条件逻辑更多的条件逻辑.
要跟进你的评论…. woocommerce_order_amount_total是数字总数而不是显示的html.您可以在cart-totals.php模板中看到正在调用的函数.
function so_38057349_woocommerce_cart_subtotal( $cart_subtotal, $compound, $cart ) {
if( $cart->subtotal == 0 ){
$cart_subtotal = __( 'Order subtotal to be determined', 'yourtheme' );
}
return $cart_subtotal;
};
add_filter( 'woocommerce_cart_subtotal', 'so_38057349_woocommerce_cart_subtotal', 10, 3 );
// define the woocommerce_order_amount_total callback
function so_38057349_woocommerce_order_amount_total( $order_total ) {
if( WC()->cart->get_total() == 0 ){
$order_total = __( 'Order total to be determined', 'yourtheme' );
}
return $order_total;
};
add_filter( 'woocommerce_cart_totals_order_total_html', 'so_38057349_woocommerce_order_amount_total' );
更新截图:
内容总结
以上是互联网集市为您收集整理的php – WooCommerce:购物车价格覆盖文字全部内容,希望文章能够帮你解决php – WooCommerce:购物车价格覆盖文字所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。