Advertisement
jigneshkaila

Display offer is pending [request] #172

Oct 2nd, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.07 KB | None | 0 0
  1. add_filter('woocommerce_get_availability', 'custom_get_availability', 1, 2);
  2.  
  3.     function custom_get_availability($availability, $_product) {
  4.  
  5.         global $product;
  6.  
  7.         $post_meta_offers_enabled = get_post_meta($product->id, 'offers_for_woocommerce_enabled', true);
  8.  
  9.         if ($post_meta_offers_enabled != "yes") {
  10.             return $availability;
  11.         } else {
  12.  
  13.             $stock = $product->get_stock_quantity();
  14.  
  15.             $woocommerce_offer_query_args = array(
  16.                 'post_type' => 'woocommerce_offer',
  17.                 'post_status' => 'accepted-offer',
  18.                 'order' => 'ASC',
  19.                 'meta_query' => array(
  20.                     array(
  21.                         'key' => 'offer_product_id',
  22.                         'value' => $product->id,
  23.                     ),
  24.                 ),
  25.             );
  26.  
  27.             $get_accepted_offer_query = new WP_Query($woocommerce_offer_query_args);
  28.  
  29.             $get_accepted_offer_query = $get_accepted_offer_query->get_posts();
  30.  
  31.             if (!empty($get_accepted_offer_query)) {
  32.                 $offer_total_quantity = 0;
  33.                 foreach ($get_accepted_offer_query as $accepted_offer) {
  34.                     $offer_quantity = get_post_meta($accepted_offer->ID, 'offer_quantity', true);
  35.                     if (isset($offer_quantity) && !empty($offer_quantity)) {
  36.                         $offer_total_quantity = $offer_total_quantity + $offer_quantity;
  37.                     }
  38.                 }
  39.                 if (!$_product->is_in_stock()) {
  40.                     $availability['availability'] = __('THIS PAINTING IS SOLD', 'woocommerce');
  41.                 } else if ($stock <= $offer_total_quantity) {
  42.                     $availability['availability'] = __('THIS PAINTING HAS AN OFFER PENDING', 'woocommerce');
  43.                 } else {
  44.                     $availability['availability'] = __('THIS PAINTING IS AVAILABLE', 'woocommerce');
  45.                 }
  46.                 return $availability;
  47.             } else {
  48.                 return $availability;
  49.             }
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement