wpgenie

add fee for auction winner on checkout

May 4th, 2017
499
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×