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 ) {
			$term = get_term_by( 'term_taxonomy_id', $term_taxonomy_id, $taxonomy );

			if ( 'availability' != strtolower( $taxonomy ) ) {
				$this->hooks_remove_meta();
				delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', $taxonomies_and_keys[ $taxonomy ] ), $term->name );
				$this->hooks_add_meta();

				do_action( 'invp_taxonomy_overlapper_deleted_meta', $object_id, $taxonomy, $term );
				continue;
			}

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

			if ( 'wholesale' == strtolower( $term->slug ) ) {
				$this->hooks_remove_meta();
				delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'wholesale' ), $term->name );
				$this->hooks_add_meta();

				do_action( 'invp_taxonomy_overlapper_deleted_meta', $object_id, $taxonomy, $term );
				continue;
			}

			// $term->slug must be for-sale or sold
			$this->hooks_remove_meta();
			delete_post_meta( $object_id, apply_filters( 'invp_prefix_meta_key', 'availability' ), $term->name );
			$this->hooks_add_meta();

			do_action( 'invp_taxonomy_overlapper_deleted_meta', $object_id, $taxonomy, $term );
		}
	}