تابع ووکامرسی wc_terms_clauses افزودن ترم به لیست get_terms

تابع ووکامرسی wc_terms_clauses افزودن ترم به لیست get_terms

تابع ووکامرسی wc_terms_clauses – افزودن ترم به لیست get_terms

Syntax – سینتکس

(array) wc_terms_clauses( (array) $clauses, (array) $taxonomies, (array) $args ); 

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

  • 1- $clauses (array)
  • 2- $taxonomies (array)
  • 3- $args (array)

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

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

Defined – محل تعریف

/includes/wc-term-functions.php

function wc_terms_clauses( $clauses, $taxonomies, $args ) { 
    global $wpdb; 
 
    // No sorting when menu_order is false. 
    if ( isset( $args['menu_order'] ) && ( false === $args['menu_order'] || 'false' === $args['menu_order'] ) ) { 
        return $clauses; 
    } 
 
    // No sorting when orderby is non default. 
    if ( isset( $args['orderby'] ) && 'name' !== $args['orderby'] ) { 
        return $clauses; 
    } 
 
    // No sorting in admin when sorting by a column. 
    if ( is_admin() && isset( $_GET['orderby'] ) ) { 
        return $clauses; 
    } 
 
    // No need to filter counts 
    if ( strpos( 'COUNT(*)', $clauses['fields'] ) !== false ) { 
        return $clauses; 
    } 
 
    // WordPress should give us the taxonomies asked when calling the get_terms function. Only apply to categories and pa_ attributes. 
    $found = false; 
    foreach ( (array) $taxonomies as $taxonomy ) { 
        if ( taxonomy_is_product_attribute( $taxonomy ) || in_array( $taxonomy, apply_filters( 'woocommerce_sortable_taxonomies', array( 'product_cat' ) ) ) ) { 
            $found = true; 
            break; 
        } 
    } 
    if ( ! $found ) { 
        return $clauses; 
    } 
 
    // Meta name. 
    if ( ! empty( $taxonomies[0] ) && taxonomy_is_product_attribute( $taxonomies[0] ) ) { 
        $meta_name = 'order_' . esc_attr( $taxonomies[0] ); 
    } else { 
        $meta_name = 'order'; 
    } 
 
    // Query fields. 
    $clauses['fields'] = 'DISTINCT ' . $clauses['fields'] . ', tm.meta_value'; 
 
    // Query join. 
    if ( get_option( 'db_version' ) < 34370 ) { 
        $clauses['join'] .= " LEFT JOIN {$wpdb->woocommerce_termmeta} AS tm ON (t.term_id = tm.woocommerce_term_id AND tm.meta_key = '" . esc_sql( $meta_name ) . "') "; 
    } else { 
        $clauses['join'] .= " LEFT JOIN {$wpdb->termmeta} AS tm ON (t.term_id = tm.term_id AND tm.meta_key = '" . esc_sql( $meta_name ) . "') "; 
    } 
 
    // Default to ASC. 
    if ( ! isset( $args['menu_order'] ) || ! in_array( strtoupper( $args['menu_order'] ), array( 'ASC', 'DESC' ) ) ) { 
        $args['menu_order'] = 'ASC'; 
    } 
 
    $order = "ORDER BY tm.meta_value+0 " . $args['menu_order']; 
 
    if ( $clauses['orderby'] ) { 
        $clauses['orderby'] = str_replace( 'ORDER BY', $order . ', ', $clauses['orderby'] ); 
    } else { 
        $clauses['orderby'] = $order; 
    } 
 
    return $clauses; 
} 

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