Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action( 'woocommerce_cart_calculate_fees', 'custom_auction_charge' );
- function custom_auction_charge( $cart_object ) {
- $spfee = 0.00; // initialize special fee, absolute amount
- $spfeeperprod = 0.20; //special fee per product, percentage
- foreach ( $cart_object->cart_contents as $key => $value ) {
- $proid = $value['product_id']; //get the product id from cart
- $quantiy = $value['quantity']; //get quantity from cart
- $product = wc_get_product( $proid ); //
- if('auction' == $product->get_type()) :
- if ($product->get_auction_closed() == 2){
- $itmprice = $value['data']->get_auction_current_bid(); //get product price
- $spfee = $spfee + $itmprice * $quantiy * $spfeeperprod;
- }
- endif;
- }
- if($spfee > 0 ) {
- WC()->cart->add_fee( 'Buyers Premium', $spfee, true, 'standard' );
- }
- }
- add_filter( 'wsa_stripe_automatic_charge_order', 'auctions_for_woocommerce_stripe_automatic_charge_addfee', 10, 2 );
- function auctions_for_woocommerce_stripe_automatic_charge_addfee( $order, $auctions_id ) {
- $fee_per_auction = 0.20; //special fee per product, percentage
- $spfee = $spfee = 0.00; // initialize special fee, absolute amount
- $product = wc_get_product( $auctions_id );
- $item_price = $product->get_auction_current_bid();
- $global_fee = $spfee + $item_price * $fee_per_auction;
- $item_fee = new WC_Order_Item_Fee();
- $item_fee->set_name( 'BPA' );
- $item_fee->set_amount( $global_fee );
- $item_fee->set_total( $global_fee );
- $order->add_item( $item_fee );
- $note = sprintf(
- __( 'WSA Stripe Auto Charge Log: This order includes a %s Buyers Premium fee.', 'woocommerce' ),
- $global_fee
- );
- $order->add_order_note( $note, true ); // true if you want the customer to see order note about fees
- return $order;
- }
Advertisement
Add Comment
Please, Sign In to add comment