wpgenie icon

add outbid badge to auction

wpgenie | PRO | 01/16/21 09:26:02 AM UTC (Edited) | 0 ⭐ | 1018 👁️ | Never ⏰ | []
PHP |

1.1 KB

|

None

|

0 👍

/

0 👎

// check also https://pastebin.com/EcmuuzHM
 
add_action('woocommerce_before_shop_loop_item_title', 'add_outbid_bage', 60);
 
function add_outbid_bage(){
    global $product,$wpdb;
    if ( is_user_logged_in() ) { 
        $auction_relisted = '';
        if($product->auction_relisted){
            $auction_relisted = ' AND date > "'. $product->auction_relisted.'"' ;
        }
        
        $user_id  = get_current_user_id();
        $postids = array();
        
        $userauction     = $wpdb->get_results("SELECT DISTINCT auction_id FROM ".$wpdb->prefix."simple_auction_log WHERE userid = $user_id AND auction_id = ".$product->id." ".$auction_relisted ,ARRAY_N );
        if(isset($userauction) && !empty($userauction)){
            foreach ($userauction as $auction) {
                $postids []= $auction[0];
 
            }
        }
        
        if ( $product->product_type == 'auction'  && ( $user_id != $product->auction_current_bider && !$product-> auction_closed) && (in_array($product->id, $postids))) : 
            echo '<span class="outbid "></span>'; 
        endif; 
    }
}

Comments