Reply To: Wallet Usage Based on few conditions and specified category2020-08-14T12:50:20+05:30

Home Forums Core Wallet Usage Based on few conditions and specified category Reply To: Wallet Usage Based on few conditions and specified category

rohitpawarindia
Participant
Post count: 2

Tried modifying the code, but still getting failed:

// wallet condition
add_filter(‘woo_wallet_partial_payment_amount’, ‘woo_wallet_partial_payment_amount_callback’, 100);
function woo_wallet_partial_payment_amount_callback($amount) {
if (sizeof(WC()->cart->get_cart()) > 0) {
$totals = WC()->cart->get_totals();

function check_product_in_cart($cat_id) {
global $woocommerce;
// id of targeted category is 5 for example

$product_count = 0;

// start of the loop that fetches the cart items

foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values[‘data’];
$terms = get_the_terms( $_product->id, ‘product_cat’ );

// second level loop search, in case some items have several categories
foreach ($terms as $term) {
$_categoryid = $term->term_id;
if ( $_categoryid === $cat_id ) {

//$product_count=+ 1 * $_product_qty;

$product = $values[‘data’];
$product_id = $values[‘product_id’];
$quantity = $values[‘quantity’];
$price = WC()->cart->get_product_price( $product );

$product_count += WC()->cart->get_product_subtotal( $product, $values[‘quantity’] );

}
}
}

return $product_count;
}

// count
$total1 = check_product_in_cart(3192);
$total2 = check_product_in_cart(3193);
$total3 = check_product_in_cart(3194);

// make total
$final_total = $total1 + $total2 + $total3;

if ( $final_total > 4999 ) {

$cart_total = $totals[‘subtotal’] + $totals[‘shipping_total’] + $totals[‘subtotal_tax’] + $totals[‘shipping_tax’];
$amount = ($cart_total * 50) / 100;
if ($amount > woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), ‘edit’)) {
$amount = woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), ‘edit’) < 250 ? woo_wallet()->wallet->get_wallet_balance(get_current_user_id(), ‘edit’) : 250;
}

}else{
$amount = 0;
}

}

return $amount;

}