Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('woocommerce_get_availability', 'custom_get_availability', 1, 2);
- function custom_get_availability($availability, $_product) {
- global $product;
- $post_meta_offers_enabled = get_post_meta($product->id, 'offers_for_woocommerce_enabled', true);
- if ($post_meta_offers_enabled != "yes") {
- return $availability;
- } else {
- $stock = $product->get_stock_quantity();
- $woocommerce_offer_query_args = array(
- 'post_type' => 'woocommerce_offer',
- 'post_status' => 'accepted-offer',
- 'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'offer_product_id',
- 'value' => $product->id,
- ),
- ),
- );
- $get_accepted_offer_query = new WP_Query($woocommerce_offer_query_args);
- $get_accepted_offer_query = $get_accepted_offer_query->get_posts();
- if (!empty($get_accepted_offer_query)) {
- $offer_total_quantity = 0;
- foreach ($get_accepted_offer_query as $accepted_offer) {
- $offer_quantity = get_post_meta($accepted_offer->ID, 'offer_quantity', true);
- if (isset($offer_quantity) && !empty($offer_quantity)) {
- $offer_total_quantity = $offer_total_quantity + $offer_quantity;
- }
- }
- if (!$_product->is_in_stock()) {
- $availability['availability'] = __('THIS PAINTING IS SOLD', 'woocommerce');
- } else if ($stock <= $offer_total_quantity) {
- $availability['availability'] = __('THIS PAINTING HAS AN OFFER PENDING', 'woocommerce');
- } else {
- $availability['availability'] = __('THIS PAINTING IS AVAILABLE', 'woocommerce');
- }
- return $availability;
- } else {
- return $availability;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement