Inventory_Presser_Taxonomy_Overlapper::term_relationship_deleted( int $object_id, array $tt_ids, string $taxonomy )
If the term relationship that was just deleted was in a vehicle taxonomy, also delete the meta value that contains the same value.
On This Page
Parameters Parameters
- $object_id
-
(int) (Required) Object ID.
- $tt_ids
-
(array) (Required) An array of term taxonomy IDs.
- $taxonomy
-
(string) (Required) Taxonomy slug.
Return Return
(void)
Source Source
File: includes/class-taxonomy-overlapper.php
public 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 = self::overlapping_meta_keys();
if ( ! in_array( $taxonomy, array_values( $keys_and_taxonomies ), true ) ) {
// No.
return;
}
$taxonomies_and_keys = self::overlapping_meta_keys_flipped();
// 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 ( is_wp_error( $term ) ) {
continue;
}
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 );
}
}
Expand full source codeCollapse full source codeView on Github