function spraypay_indrie_cart( $total, $cart_item, $cart_item_key ) {

    //Get product object
    $_product = $cart_item['data'];
      $prodid = $_product->get_id();
      $prijs = wc_get_price_to_display($_product) * $cart_item['quantity'];
      $indrie = get_field('in3',$prodid);
      $factor = 0.03317;
      $in3bedrag = $prijs / 3;
      $maandbedrag = $prijs * $factor;
      $bedragformatted = ' <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">€</span>'.number_format($maandbedrag, 2, ',', '').'</span> ';
      $in3bedragformatted = ' <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">€</span>'.number_format($in3bedrag, 2, ',', '').'</span> ';
      $in3text = __( 'of', 'spraypay' ) . $in3bedragformatted . __( 'in 3 termijnen', 'beryl' );
      $textafter = __( 'of', 'spraypay' ) . $bedragformatted . __( 'in 36 termijnen', 'beryl' );

      if($indrie){ // als vinkje in3 is gezet
          if( !has_term( array( 'smartphone' ), 'product_cat' ) && $prijs >= 250): // voer de code alleen uit als het product meer dan 250 euro kost en het NIET in de categorie smartphone zit
          return $total . '<br /><span class="trms">' . $in3text . '</span><br /><span class="trms">' . $textafter . '</span>';
        else:
          return $total . '<br /><span class="trms">' . $in3text . '</span>';
        endif;
      } elseif( !has_term( array( 'smartphone' ), 'product_cat' ) && $prijs >= 250) {
        return $total . '<br /><span class="trms">' . $textafter . '</span>';
      } else {
        return $total;
      };

}
add_filter( 'woocommerce_cart_item_subtotal', 'spraypay_indrie_cart', 10, 3 );
Geef een reactie 0