Inventory_Presser_Taxonomy_Overlapper::term_relationship_updated( int $object_id, array $terms, array $tt_ids, string $taxonomy, bool $append, array $old_tt_ids )

term_relationship_updated


Parameters Parameters

$object_id

(int) (Required) Object ID.

$terms

(array) (Required) An array of object terms.

$tt_ids

(array) (Required) An array of term taxonomy IDs.

$taxonomy

(string) (Required) Taxonomy slug.

$append

(bool) (Required) Whether to append new terms to the old terms.

$old_tt_ids

(array) (Required) Old array of term taxonomy IDs.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-taxonomy-overlapper.php

	function term_relationship_updated( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids )
	{
		//Does $object_id belong to a vehicle?
		if( INVP::POST_TYPE != get_post_type( $object_id ) )
		{
			//No
			return;
		}

		//Is the taxonomy one that overlaps a meta field?
		$keys_and_taxonomies = $this->overlapping_meta_keys();
		$taxonomies_and_keys = array_flip( $keys_and_taxonomies );
		if( ! in_array( $taxonomy, array_values( $keys_and_taxonomies ) ) )
		{
			//No
			return;
		}

		//An empty array of terms is passed often
		if( empty( $terms ) )
		{
			return;
		}

		foreach( $terms as $term_id )
		{
			$term = get_term( $term_id, $taxonomy );
			if( ! is_object( $term ) || 'WP_Term' != get_class( $term ) )
			{
				continue;
			}

			//For most taxonomies, we can just save the term name in the post meta field
			if( 'availability' != $taxonomy )
			{
				$this->hooks_remove();
				update_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', $taxonomies_and_keys[$taxonomy] ), $term->name );
				$this->hooks_add();
				continue;
			}

			//The availability taxonomy was the one updated
			switch( $term->slug )
			{
				case "for-sale":
				case "sold":
					$this->hooks_remove();
					update_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'availability' ), $term->name );
					$this->hooks_add();
					break;

				case "wholesale":
					$this->hooks_remove();
					update_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'wholesale' ), true );
					$this->hooks_add();
					break;
			}
		}
	}