PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-仅在Woocommerce结帐页面中将文本追加到总价中大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我有以下代码,在购物车和结帐页面的总计部分中添加了后缀文本:

add_filter( 'woocommerce_cart_@R_773_10586@l', 'custom_@R_773_10586@l_message' );
function custom_@R_773_10586@l_message( $price ) {
    $msg = 'Prices for grocery items may vary at store. Final bill will be based on store receipt.<br />';

    return $price . $msg;
}

但是,我只希望后缀文本仅显示在结帐页面,而不显示在购物车页面.

我该如何完成?

解决方法:

只需使用Woocommerce conditional tags即可仅限制结帐页面上的显示

现在,您最好改用以下钩子,以避免出现问题,将浮点数与小数点上的数字进行融合:

add_filter( 'woocommerce_cart_@R_773_10586@ls_order_@R_773_10586@l_html', 'custom_@R_773_10586@l_message_html', 10, 1 );
function custom_@R_773_10586@l_message_html( $value ) {
    if( is_checkout() )
        $value .= __('Prices for grocery items may vary at store. Final bill will be based on store receipt.') . '<br />';

    return $value;
}

甚至在总计之后的单独表格行上更好,使用以下方法代替:

add_action( 'woocommerce_review_order_after_order_@R_773_10586@l', 'review_order_after_order_@R_773_10586@l_callBACk' );
function review_order_after_order_@R_773_10586@l_callBACk(){
    $text = __('Prices for grocery items may vary at store. Final bill will be based on store receipt.');

    ?><tr class="order-@R_773_10586@l"><th colspan="2"><?PHP echo $text; ?></th></tr><?PHP
}

您的活动子主题(或主题)的function.PHP文件中包含代码.经过测试和工作.

如果决定保留初始钩子,请使用以下命令:

add_filter( 'woocommerce_cart_@R_773_10586@l', 'custom_@R_773_10586@l_message', 10, 1 );
function custom_@R_773_10586@l_message( $price ) {
    if( is_checkout() )
        $price .= __('Prices for grocery items may vary at store. Final bill will be based on store receipt.') . '<br />';

    return $price;
}

您的活动子主题(或主题)的function.PHP文件中包含代码.未经测试.

大佬总结

以上是大佬教程为你收集整理的php-仅在Woocommerce结帐页面中将文本追加到总价中全部内容,希望文章能够帮你解决php-仅在Woocommerce结帐页面中将文本追加到总价中所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: