如何解决在WooCommerce中通过网址变量GET申请费用
我正在尝试将“ add_fee”值保留下来以查看订单页面,但它不起作用。
我需要启用我的检出页面以等待url参数“ getfee”。
如果getfee等于2,则添加费用。
如果没有,则不要添加任何内容。
这是我的代码:
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_surcharge' );
function woocommerce_custom_surcharge() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$fee = $_GET["getfee"];
if( $fee == "2") {
$percentage = 0.01;
$surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$woocommerce->cart->add_fee( 'Surcharge',$surcharge,true,'' );
}
}
到目前为止,它会在结帐页面中添加费用,但在查看订单时却没有出现。
我认为可能是因为结帐页面没有该参数,但不确定。
任何帮助将不胜感激。
解决方法
您需要在WC Session变量中设置“网址费用”,以避免出现此问题:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" id="actions-container">
<div class="d-flex justify-content-between">
<div class="action-icon-box text-center ">
<div class="right-arc">
</div>
<h3 class="text-center">Title</h3>
<div class="p-1 action-icon text-center mt-4">
<a href="#"><img class="center" src="/Content/images/lp-homepage/microphone.png" height="100" /></a>
</div>
</div>
</div>
</div>
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。