php - 当我未登录 Wordpress 时,该功能有效。但是,当我登录时,它不起作用
问题描述
我有一个功能,我想根据一些计算添加费用。该功能在我未登录网站时有效,但在我登录时无效。登录时,Cart
页面不显示任何内容(没有产品或其他任何内容);它只显示一个标题为“购物车”的白页,仅此而已。这是我的代码:
function prefix_add_discount_linett( $cart ) {
$termID = $_SESSION['clicked'];
// get the quantity total number of the category that have ID '16' and the products options must be "sénior" or "méga".
function cat_cart_count( $cat_name, $termID ) {
$termID = $_SESSION['clicked'];
$cat_count = 0;
foreach(WC()->cart->get_cart() as $cart_item)
if( (has_term( $cat_name, 'product_cat', $cart_item['product_id']) && $cart_item['yith_wapo_options'][0]['value']=='sénior') || (has_term( $cat_name, 'product_cat', $cart_item['product_id']) && $cart_item['yith_wapo_options'][0]['value']=='méga')){
$cat_count += $cart_item['quantity'];
}else{
continue;
}
// on this one, I have two buttons one is delivery and in this one it is take_away so take away must check if the number is divisible into two or not and I must alawys get an integer number, but when I choose Delivery check if the number is divisible into three or not and I must alawys get an integer number as well.
if($termID=="take_away"){
if ($cat_count%2 == 1) {
$cat_count=$cat_count/2;
floor($cat_count);
}else{
$cat_count=$cat_count/2;
floor($cat_count);
}
}else{
if ($cat_count%3 == 0) {
$cat_count=$cat_count/3;
floor($cat_count);
}else{
$cat_count=$cat_count/3;
floor($cat_count);
}
}
return floor($cat_count);
}
cat_cart_count( 16 );
// this function is for getting the minimal price of the category '16' with the options "sénior" or "méga".
function cat_cart_prix_min( $cat_name ) {
$testprix = 900000;
foreach(WC()->cart->get_cart() as $cart_item)
if( (has_term( $cat_name, 'product_cat', $cart_item['product_id']) && $cart_item['yith_wapo_options'][0]['value']=='sénior') || (has_term( $cat_name, 'product_cat', $cart_item['product_id']) && $cart_item['yith_wapo_options'][0]['value']=='méga')){
if ($testprix>$cart_item['yith_wapo_options'][0]['price_original']) {
$testprix = $cart_item['yith_wapo_options'][0]['price_original'];
}else{
continue;
}
}else{
continue;
}return $testprix;
}
if($termID=="delivery" || $termID=="take_away"){
$prixmin = cat_cart_prix_min(16);
$total_QN = cat_cart_count( $cat_name );
// this variable '$simo' it count the total of the quantities multiplied by the minimal price ($simo = quantities * minimal price)
$simo = $total_QN*$prixmin;
}
// this one is for counting the fees
$discount = $simo;
if($discount>0){
$cart->add_fee( __( 'Offertes', 'yourtext-domain' ) , -$discount );
}
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_linett' );
解决方案
推荐阅读
- java - Android 的 Ionic cordova 构建失败?
- javascript - 为什么我不能在 .keys() 的结果上调用 .join()?
- javascript - 如何在将数据从 php 获取到 javascript 文件时解决成功问题?
- mysql - 如何获取行
- javascript - 使用vuejs加载页面时如何从firebase获取数据?
- java - 如何随机化Java“if”语句顺序或执行顺序代码?
- python - 仅在双击事件时允许编辑表格小部件项目
- ios - 如何使用 swift 下载和共享 pdf 文件
- javascript - 如何在 React Native 中更改默认导航动画
- html - 文本溢出时自动“可折叠”或“手风琴”