0

I'm trying to add a deposit option just for backorder items, I found this code on here but still show's up for ALL items, not just BACKORDER, I'm trying to fix this

enter image description here

add_action( 'woocommerce_cart_calculate_fees', 'calculated_deposit_discount_on_backorders' );
function calculated_deposit_discount_on_backorders( $cart ) {

if ( is_admin() && ! defined( 'DOING_AJAX' ) )
    return;

## Set HERE your negative percentage (to remove an amount from cart total)
$percent = -.50; // 50% off (negative)

$backordered_amount = 0;

foreach( $cart->get_cart() as $cart_item ) {
    if( $cart_item['data']->is_on_backorder( $cart_item['quantity'] ) ) {
        $backordered_amount += $cart_item['line_total'] + $cart_item['line_tax'];
    }
}

## ## CALCULATION ## ##
$calculated_amount = $backordered_amount * $percent;

// Adding a negative fee to cart amount (Including taxes)
$cart->add_fee( __('Depósito 50%', 'woocommerce'), $calculated_amount, true );

}

Ale
  • 25
  • 5
  • **1)** Please read: [How to reference material written by others](https://stackoverflow.com/help/referencing). **2)** You just need to add an extra if condition `if ( $backordered_amount > 0 ) { $calculated_amount = ..` – 7uc1f3r Jun 09 '22 at 06:43
  • @7uc1f3r thanks, but what I was trying to do is REMOVE the deposit option ONLY when there are NO Backordered products in cart – Ale Jun 18 '22 at 02:55
  • If you believe your question is not a duplicate, edit it (don't add the explanation as a comment) so that your question is added to the review queues after your edit. That way, your question (if it meets the criteria) will be reopened. P.s. what you seem to forget is that Stack Overflow is not a code-writing or tutoring service. It's not just about copying and pasting existing code and then assuming that someone will provide the changes you want, you should at least show your own code attempt. – 7uc1f3r Jun 20 '22 at 09:30

0 Answers0