Inventory_Presser_Taxonomy_Overlapper::term_relationship_deleted( int $object_id, array $tt_ids, string $taxonomy )

term_relationship_deleted


Description Description

If the term relationship that was just deleted was in a vehicle taxonomy, also delete the meta value that contains the same value.


Top ↑

Parameters Parameters

$object_id

(int) (Required) Object ID.

$tt_ids

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

$taxonomy

(string) (Required) Taxonomy slug.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class-taxonomy-overlapper.php

	function term_relationship_deleted( $object_id, $tt_ids, $taxonomy )
	{
		//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;
		}

		//delete post meta values from this post 
		foreach( $tt_ids as $term_taxonomy_id )
		{
			if( 'availability' != $taxonomy )
			{
				$this->hooks_remove();
				delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', $taxonomies_and_keys[$taxonomy] ) );
				$this->hooks_add();
				continue;
			}

			//The availability taxonomy can contain more than one term, so don't just blindly delete
			$term = get_term_by( 'term_taxonomy_id', $term_taxonomy_id, $taxonomy );
			if( empty( $term->slug ) )
			{
				continue;
			}

			if( 'wholesale' == $term->slug )
			{
				$this->hooks_remove();
				delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'wholesale' ) );
				$this->hooks_add();
				continue;
			}

			//$term->slug must be for-sale or sold
			$this->hooks_remove();
			delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'availability' ) );
			$this->hooks_add();
		}
	}