Inventory_Presser_WP_All_Import::set_availability_for_sale( int $post_id )

Not all feed imports have a for sale/sold bit that matches up nicely with our Availability taxonomy. Mark vehicles as for sale if no relationship exists in the taxonomy.

On This Page


Parameters Parameters

$post_id

(int) (Required) The inserted or updated post ID.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/integrations/class-wp-all-import.php

	public function set_availability_for_sale( $post_id ) {
		// Is it a vehicle?
		if ( ! class_exists( 'INVP' ) || INVP::POST_TYPE !== get_post_type( $post_id ) ) {
			// No.
			return;
		}

		$taxonomy = 'availability';
		if ( ! empty( wp_get_object_terms( $post_id, $taxonomy ) ) ) {
			// There is already a relationship.
			return;
		}

		// Do we have a For Sale term?
		$term = get_term_by( 'slug', 'for-sale', $taxonomy );
		if ( $term ) {
			// Yes, create the relationship.
			wp_set_object_terms( $post_id, $term->term_id, $taxonomy );
		}
	}