wpgenie

custom_auction_is_purchasable

Jan 14th, 2021
497
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_action( 'init', 'custom_remove_add_filters' );
  2.  
  3. function custom_remove_add_filters(){
  4.     global $woocommerce_auctions;
  5.     remove_filter( 'woocommerce_is_purchasable', array( $woocommerce_auctions, 'auction_is_purchasable' ), 10 );
  6.     add_filter( 'woocommerce_is_purchasable', 'custom_auction_is_purchasable' , 10, 2 );
  7. }
  8.  
  9. function custom_auction_is_purchasable( $is_purchasable, $object ) {
  10.  
  11.     $object_type = method_exists( $object, 'get_type' ) ? $object->get_type() : $object->product_type;
  12.     if ( $object_type == 'auction' ) {
  13.  
  14.         if ( get_option( 'simple_auctions_alow_buy_now', 'yes' ) == 'no' && $object->get_auction_bid_count() != '0' && $object->get_auction_closed() != '2' ) {
  15.             return false;
  16.         }
  17.         if ( ! $object->get_auction_closed() && ! $object->get_auction_closed() && $object->get_price() !== '' ) {
  18.  
  19.             return true;
  20.         }
  21.  
  22.         if ( ! is_user_logged_in() ) {
  23.             return false;
  24.         }
  25.  
  26.         $current_user = wp_get_current_user();
  27.         if ( $current_user->ID != $object->get_auction_current_bider() ) {
  28.             return false;
  29.         }
  30.  
  31.         if ( ! $object->get_auction_closed() ) {
  32.             return false;
  33.         }
  34.         if ( $object->get_auction_closed() != '2' ) {
  35.             return false;
  36.         }
  37.         if ( $object->get_auction_type() == 'reverse' && get_option( 'simple_auctions_remove_pay_reverse' ) == 'yes' ) {
  38.             return false;
  39.         }
  40.  
  41.         return true;
  42.     }
  43.     return $is_purchasable;
  44. }
RAW Paste Data