تابع ووکامرسی wc_get_related_products نمایش دیگر محصولات مرتبط
تابع ووکامرسی wc_get_related_products – نمایش دیگر محصولات مرتبط بر اساس دسته یا تگ محصول
Syntax – سینتکس
(array) wc_get_related_products( (int) $product_id, (int) $limit = 5, (array) $exclude_ids = array() );
Parameters – پارامتر ها (3)
- 1- $product_id (int)
- 2- $limit (int)
- 3- $exclude_ids (array)
Usage – نحوه استفاده
if ( !function_exists( 'wc_get_related_products' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; } // The product id. $product_id = -1; // Limit of results. $limit = 5; // Exclude IDs from the results. $exclude_ids = array(); // NOTICE! Understand what this does before running. $result = wc_get_related_products($product_id, $limit, $exclude_ids);
Defined – محل تعریف
/includes/wc-product-functions.php
function wc_get_related_products( $product_id, $limit = 5, $exclude_ids = array() ) { global $wpdb; $product_id = absint( $product_id ); $exclude_ids = array_merge( array( 0, $product_id ), $exclude_ids ); $transient_name = 'wc_related_' . $product_id; $related_posts = get_transient( $transient_name ); $limit = $limit > 0 ? $limit : 5; // 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 ) ? 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 ) ) { $related_posts = array(); } else { $data_store = WC_Data_Store::load( 'product' ); $related_posts = $data_store->get_related_products( $cats_array, $tags_array, $exclude_ids, $limit + 10, $product_id ); } set_transient( $transient_name, $related_posts, DAY_IN_SECONDS ); } shuffle( $related_posts ); return array_slice( $related_posts, 0, $limit ); }
versions – نسخه ها
از نسخه : 3.0.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر