تابع ووکامرسی wc_change_term_counts تغییر شمارش محصول در دسته و تگ

تابع ووکامرسی wc_change_term_counts تغییر شمارش محصول در دسته و تگ

تابع ووکامرسی wc_change_term_counts – تغییر شمارش محصول در دسته و تگ ووکامرس

Syntax – سینتکس

(array) wc_change_term_counts( (array) $terms, (string|array) $taxonomies ); 

Parameters – پارامتر ها (2)

  • 1- $terms (array)
  • 2- $taxonomies (string|array)

Usage – نحوه استفاده

if ( !function_exists( 'wc_change_term_counts' ) ) { 
    require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-term-functions.php'; 
} 
  
// The terms. 
$terms = array(); 
  
// The taxonomies. 
$taxonomies = null; 
  
// NOTICE! Understand what this does before running. 
$result = wc_change_term_counts($terms, $taxonomies); 
    

Defined – محل تعریف

/includes/wc-term-functions.php

function wc_change_term_counts( $terms, $taxonomies ) { 
    if ( is_admin() || is_ajax() ) { 
        return $terms; 
    } 
 
    if ( ! isset( $taxonomies[0] ) || ! in_array( $taxonomies[0], apply_filters( 'woocommerce_change_term_counts', array( 'product_cat', 'product_tag' ) ) ) ) { 
        return $terms; 
    } 
 
    $term_counts = $o_term_counts = get_transient( 'wc_term_counts' ); 
 
    foreach ( $terms as &$term ) { 
        if ( is_object( $term ) ) { 
            $term_counts[ $term->term_id ] = isset( $term_counts[ $term->term_id ] ) ? $term_counts[ $term->term_id ] : get_woocommerce_term_meta( $term->term_id, 'product_count_' . $taxonomies[0] , true ); 
 
            if ( '' !== $term_counts[ $term->term_id ] ) { 
                $term->count = absint( $term_counts[ $term->term_id ] ); 
            } 
        } 
    } 
 
    // Update transient 
    if ( $term_counts != $o_term_counts ) { 
        set_transient( 'wc_term_counts', $term_counts, DAY_IN_SECONDS * 30 ); 
    } 
 
    return $terms; 
} 

versions – نسخه ها

از نسخه : 3.0.2

نسخه فعلی : 3.0.6

دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2

ارسال نظر

جهت استفاده از کد حتما از تگ pre استفاده نمایید .

contact us