1. Home
  2. ReHub Theme
  3. Advanced tips and customizations
  4. Make draft post if Offer price field is empty

Make draft post if Offer price field is empty

When you use Content Egg plugin, you may have post synchronization in theme option – affiliate.

Sometimes, your synchronized offer can be expired. For example, if you promote Ebay offer. In this case, theme will not delete such post, because it can still have some traffic. But, user can be confused if he clicks on such offer and find that page is expired on destination site.

To prevent this, you can add additional function to make such posts as draft or as expired.

This is function to make post as draft (so, it will not be visible on site).

add_action('content_egg_save_data', 'rehub_save_meta_ce_after', 14, 3);
function rehub_save_meta_ce_after($data, $module_id, $post_id){
  if (!$post_id){
    global $post;
    if (isset($post)){
      $post_id = $post->ID;
    }
    else{
      return false; // Error: no POST ID
    }
  }
    $cegg_field_array = rehub_option('save_meta_for_ce');
    $cegg_fields = array();
    if (!empty($cegg_field_array) && is_array($cegg_field_array)) {
    	foreach ($cegg_field_array as $cegg_field) {
        	$cegg_field_value = \ContentEgg\application\components\ContentManager::getViewData($cegg_field, $post_id);
    		if (!empty ($cegg_field_value) && is_array($cegg_field_value)) {
                foreach ($cegg_field_value as $key => $value) {
                    $value['module_id'] = $cegg_field;
                    $cegg_fields[$key] = $value;
                }     			
    			//$cegg_fields += $cegg_field_value;
    		}		
    	}
    	usort($cegg_fields, 'rehub_sort_price_ce');
    }
  if (!empty($cegg_field_array) && is_array($cegg_field_array)) {
    if (!empty($cegg_fields) && is_array($cegg_fields)) {
    		if(empty ($cegg_fields[0]['price'])) {
        $my_post = array();
      		$my_post['ID'] = $post_id; 
      		$my_post['status'] = 'draft';
      		wp_update_post( $my_post );		  		   			
    		}
    	}
    }	
}

This function can make post as expired

add_action('content_egg_save_data', 'rehub_save_meta_ce_after', 14, 3);
function rehub_save_meta_ce_after($data, $module_id, $post_id){
  if (!$post_id){
    global $post;
    if (isset($post)){
      $post_id = $post->ID;
    }
    else{
      return false; // Error: no POST ID
    }
  }
    $cegg_field_array = rehub_option('save_meta_for_ce');
    $cegg_fields = array();
    if (!empty($cegg_field_array) && is_array($cegg_field_array)) {
    	foreach ($cegg_field_array as $cegg_field) {
        	$cegg_field_value = \ContentEgg\application\components\ContentManager::getViewData($cegg_field, $post_id);
    		if (!empty ($cegg_field_value) && is_array($cegg_field_value)) {
                foreach ($cegg_field_value as $key => $value) {
                    $value['module_id'] = $cegg_field;
                    $cegg_fields[$key] = $value;
                }     			
    			//$cegg_fields += $cegg_field_value;
    		}		
    	}
    	usort($cegg_fields, 'rehub_sort_price_ce');
    }
  if (!empty($cegg_field_array) && is_array($cegg_field_array)) {
    if (!empty($cegg_fields) && is_array($cegg_fields)) {
    		if(empty ($cegg_fields[0]['price'])) {
                update_post_meta($post_id, 're_post_expired', 1);	  		   			
    		}
    	}
    }	
}

Add this to functions.php of child theme or grandchild plugin. How to customize theme

P.s. How to make grey-scale color post with expired offer

 

Was this article helpful to you? Yes No

How can we help?