wc_get_product_term_ids instead of related wording and use in other places.

get_the_terms is used here and also handles caching, something
wp_get_post_terms does not.
This commit is contained in:
Mike Jolley 2016-10-17 17:18:57 +01:00
parent e6e600ba8a
commit 50f21276fc
2 changed files with 9 additions and 11 deletions

View File

@ -32,11 +32,11 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
/**
* Retrieves related product terms.
* @deprecated 2.7.0 Use wc_get_related_terms instead.
* @deprecated 2.7.0 Use wc_get_product_term_ids instead.
*/
protected function get_related_terms( $term ) {
_deprecated_function( 'WC_Product::get_related_terms', '2.7', 'wc_get_related_terms' );
return array_merge( array( 0 ), wc_get_related_terms( $this->get_id(), $term ) );
_deprecated_function( 'WC_Product::get_related_terms', '2.7', 'wc_get_product_term_ids' );
return array_merge( array( 0 ), wc_get_product_term_ids( $this->get_id(), $term ) );
}
/**

View File

@ -700,7 +700,7 @@ function wc_get_product_variation_attributes( $variation_id ) {
* @return array
*/
function wc_get_product_cat_ids( $product_id ) {
$product_cats = wp_get_post_terms( $product_id, 'product_cat', array( "fields" => "ids" ) );
$product_cats = wc_get_product_term_ids( $product_id, 'product_cat' );
foreach ( $product_cats as $product_cat ) {
$product_cats = array_merge( $product_cats, get_ancestors( $product_cat, 'product_cat' ) );
@ -772,8 +772,8 @@ function wc_get_related_products( $product_id, $limit = 5, $exclude_ids = array(
// We want to query related posts if they are not cached, or we don't have enough.
if ( false === $related_posts || count( $related_posts ) < $limit ) {
$cats_array = apply_filters( 'woocommerce_product_related_posts_relate_by_category', true, $product_id ) ? wc_get_related_terms( $product_id, 'product_cat' ) : array();
$tags_array = apply_filters( 'woocommerce_product_related_posts_relate_by_tag', true, $product_id ) ? wc_get_related_terms( $product_id, 'product_tag' ) : array();
$cats_array = apply_filters( 'woocommerce_product_related_posts_relate_by_category', true, $product_id ) ? apply_filters( 'woocommerce_get_related_product_cat_terms', wc_get_product_term_ids( $product_id, 'product_cat' ), $product_id ) : array();
$tags_array = apply_filters( 'woocommerce_product_related_posts_relate_by_tag', true, $product_id ) ? apply_filters( 'woocommerce_get_related_product_tag_terms', wc_get_product_term_ids( $product_id, 'product_tag' ), $product_id ) : array();
// Don't bother if none are set, unless woocommerce_product_related_posts_force_display is set to true in which case all products are related.
if ( empty( $cats_array ) && empty( $tags_array ) && ! apply_filters( 'woocommerce_product_related_posts_force_display', false, $product_id ) ) {
@ -792,17 +792,15 @@ function wc_get_related_products( $product_id, $limit = 5, $exclude_ids = array(
}
/**
* Retrieves related product terms.
* Retrieves product term ids for a taxonomy.
*
* @since 2.7.0
* @param int $product_id Product ID.
* @param string $taxonomy Taxonomy slug.
* @return array
*/
function wc_get_related_terms( $product_id, $taxonomy ) {
$terms = apply_filters( 'woocommerce_get_related_' . $taxonomy . '_terms', get_the_terms( $product_id, $taxonomy ), $product_id );
return array_map( 'absint', wp_list_pluck( $terms, 'term_id' ) );
function wc_get_product_term_ids( $product_id, $taxonomy ) {
return wp_list_pluck( get_the_terms( $product_id, $taxonomy ), 'term_id' );
}
/**