Search
 
SCRIPT & CODE EXAMPLE
 

PHP

woocommerce get product id

global $product;
$product->get_id();
Comment

woocommerce get product category name by id

$id = 42;
if( $term = get_term_by( 'id', $id, 'product_cat' ) ){
    echo $term->name;
}
Comment

woocommerce get product categories

$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
    $product_cat_id[] = $term->term_id;
}
Comment

get woocommerce product category link by id

global $post;
$link = '';
$terms = get_the_terms( $post->ID, 'product_cat' );
if(!empty($terms[0])){
    $link = get_term_link( $terms[0]->term_id, 'product_cat' );
}
Comment

woocommerce get product id by category id

$p_array=['12','16', '21', '17'];
$prod_array= array();
foreach( $p_array as $key=>$value) {

			$term_object = get_term( $value );
			$cat_name= $term_object->slug;
			//echo $cat_name;
			$all_ids = get_posts( array(
				'post_type' => 'product',
				'numberposts' => -1,
				'post_status' => 'publish',
				'fields' => 'ids',
				'tax_query' => array(
					array(
						'taxonomy' => 'product_cat',
						'field' => 'slug',
						'terms' => $cat_name,
						'operator' => 'IN',
					)
				),
			) );
			foreach ( $all_ids as $id ) {
				array_push($prods_array, $id);
			}
		 }
        print_r($prod_array); 
Comment

wordpress get product category name by termid

// Testing that $_GET['product-cato'] has been requested and that the product category exists.
if( isset( $_GET['product-cato'] ) && term_exists( intval($_GET['product-cato']), 'product_cat' ) ){
    // Get the corresponding WP_Term object
    $term = get_term( intval($_GET['product-cato']), 'product_cat' );
    //Display the term name for the product category
    echo '<p>' . $term->name . '</p>';
}
Comment

PREVIOUS NEXT
Code Example
Php :: error repoerting in php 
Php :: response()-make laravel pdf 
Php :: laravel migration remove unique 
Php :: eliminar ultimo caracter string php 
Php :: taxonomy acf 
Php :: Session store not set on request. 
Php :: get table name from model laravel 
Php :: php insert character into string 
Php :: get array key php 
Php :: http error code php 
Php :: php array_values 
Php :: php to call javascript function 
Php :: delete method laravel 
Php :: update sql php 
Php :: acf options repeater 
Php :: how do decode base64 php 
Php :: laravel migration seed fresh 
Php :: add to collection laravel 
Php :: Failed to authenticate on SMTP server with username 
Php :: laravel 8 created at format 
Php :: br php 
Php :: remove last character from string in php 
Php :: php get highest key value 
Php :: random array php 
Php :: pass variable to another page in js 
Php :: Remove public or index file from url in laravel 
Php :: merge two arrays one as key to another php 
Php :: session variable in laravel 
Php :: associative array sorting by value in php 
Php :: how validate array in laravel in request 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =