Advertisement
wpgenie

add fee for auction winner on checkout

May 4th, 2017
2,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. add_action( 'woocommerce_cart_calculate_fees', 'custom_auction_charge' );  
  2.  
  3. function custom_auction_charge( $cart_object ) {
  4.  
  5.     $spfee = 0.00; // initialize special fee
  6.     $spfeeperprod = 0.20; //special fee per product
  7.  
  8.     foreach ( $cart_object->cart_contents as $key => $value ) {
  9.  
  10.         $proid = $value['product_id']; //get the product id from cart
  11.         $quantiy = $value['quantity']; //get quantity from cart
  12.         $product = wc_get_product( $proid  ); //
  13.  
  14.         if('auction' == $product->get_type()) :
  15.  
  16.             if ($product->get_auction_closed() == 2){
  17.                     $itmprice = $value['data']->get_auction_current_bid(); //get product price 
  18.                     $spfee = $spfee + $itmprice * $quantiy * $spfeeperprod;
  19.             }      
  20.         endif;  
  21.  
  22.     }
  23.     if($spfee > 0 ) {
  24.         WC()->cart->add_fee( 'Buyers Premium', $spfee, true, 'standard' );
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement