У меня есть функция, где я хочу добавить сборы на основе некоторых расчетов. Функция работает, когда я не захожу на сайт, но не работает, когда я захожу. 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' );
Задача ещё не решена.
Других решений пока нет …