wc-quick-donation-functions.php 2.09 KB
Newer Older
Varun Sridharan's avatar
Varun Sridharan committed
1 2
<?php

3 4
if(! function_exists('wcqd_get_message')){
    function wcqd_get_message($id,$search_replace = array()){
Varun Sridharan's avatar
Varun Sridharan committed
5 6 7
        $message = WC_QD()->db()->get_message($id,$search_replace);
        return $message;
    }
8 9
} 

Varun Sridharan's avatar
Varun Sridharan committed
10 11 12 13 14 15 16 17 18
if(! function_exists('wcqd_is_donation')){
    function wcqd_is_donation($order_id = ''){
        if(empty($order_id)){return false;}
        $is_donation = WC_QD()->db()->_is_donation($order_id);
        return $is_donation;
    }
}


19
if(! function_exists('wcqd_project_limit')){
Varun Sridharan's avatar
Varun Sridharan committed
20 21 22 23 24 25
    /**
     * To Get Projects Min & Max Limit
     * @param  [int] [$project_id = 0] [Post id of the donation project]
     * @param  [int] [$type = 'min']   [use min / max to get the limit]
     * @return [int] [return limit value]
     */
26
    function wcqd_project_limit($project_id = 0, $type = 'min'){
27 28 29 30 31 32
        if(empty($project_id)){return false; }
        if($type !== 'min' && $type !== 'max'){return false;}
        $function_toCal = $type.'_project';
        $limit = WC_QD()->db()->{$function_toCal}($project_id);
        return $limit;
}
Varun Sridharan's avatar
Varun Sridharan committed
33 34
}

Varun Sridharan's avatar
Varun Sridharan committed
35 36 37 38 39 40 41
if(! function_exists('wcqd_get_project_from_order')){
    /**
     * Returns Project ID From Order ID
     * @param  [int] [$order_id = ''] [pass the order id to get the project id]
     * @return int / boolean  [returns project id if exist or returns false]
     */
    function wcqd_get_project_from_order($order_id = ''){ 
42 43 44 45 46 47
        $is_donation = WC_QD()->db()->_is_donation($order_id);
        if($is_donation){
            $project = WC_QD()->db()->get_project_id($order_id);
            return $project;
        } 
        return false;
Varun Sridharan's avatar
Varun Sridharan committed
48 49 50
    }
}

51
if(! function_exists('wcqd_get_project_name')){
Varun Sridharan's avatar
Varun Sridharan committed
52 53 54 55 56
    /**
     * Returns Project Title From Order ID
     * @param  [int] [$order_id = ''] [pass the order id to get the project title]
     * @return int / boolean  [returns project id if exist or returns false]
     */
57
    function wcqd_get_project_name($order_id = '', $default_title = ''){  
Varun Sridharan's avatar
Varun Sridharan committed
58
        $project_id = wcqd_get_project_from_order($order_id); 
59
        $title = get_the_title($project_id);
60
        if(empty($title)){return $default_title;}
61
        return $title;
Varun Sridharan's avatar
Varun Sridharan committed
62 63
    }
}
64

Varun Sridharan's avatar
Varun Sridharan committed
65
   
Varun Sridharan's avatar
Varun Sridharan committed
66
?>