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

woocommerce php get product attributes

$result = array_shift(woocommerce_get_product_terms($product->id, 'pa_koostis', 'names'));
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

woocommerce php get product attributes

global $product;
$koostis = $product->get_attribute( 'pa_koostis' );
Comment

woocommerce php get product attributes

global $product;
$koostis = array_shift( wc_get_product_terms( $product->id, 'pa_koostis', array( 'fields' => 'names' ) ) );
Comment

get all products for a current woocommerce product

/**
 *
 *  Add Product Tags Above The Add To Cart Form
 *
 */
add_action( 'woocommerce_before_add_to_cart_form', 'dwc_print_tags_under_description' );
function dwc_print_tags_under_description() {
 
    // This will hold all of our product tags
    $tags = array();
 
    // get an array of the WP_Term objects for a defined product ID (get_the_id() will return the product id of the current object)
    $terms = wp_get_post_terms( get_the_id(), 'product_tag' );
 
    // Loop through each product tag for the current product
    if ( count( $terms ) > 0 ) {
 
        foreach( $terms as $term ) {
 
            // Product Tag Name
            $term_name = $term->name;
 
            // Product Tag Link
            $term_link = get_term_link( $term, 'product_tag' );
 
            // Set the product tag names in an array
            $tags[] = '<a class="product-tag-badge" href="'.$term_link.'">' . $term_name . '</a>';
 
        }
 
        // Combine all of the product tags into one string for output
        $tags = implode( '', $tags );
 
        // Output
        echo $tags;
    }
 
}
Comment

woocommerce get product variations

Woocommerce product data
Comment

PREVIOUS NEXT
Code Example
Php :: laravel route group name 
Php :: Carbon Add Days To Date In Laravel 
Php :: php insert hyphen into spaces in string 
Php :: php number to color 
Php :: php.ini path 
Php :: php syntax 
Php :: php ternary operator 
Php :: symfony password generator command line 
Php :: show created_at as normal date laravel blade 
Php :: php change array into comma delimited string 
Php :: make model and migration in laravel 
Php :: strval in php 
Php :: wordpress query multiple post ids 
Php :: sleep php 
Php :: How can I get current controller and current controller action name in yii2 
Php :: return back in blade laravel 
Php :: return view controller laravel 
Php :: php for loop array 
Php :: use ternary operator as null coalescing operator in php 
Php :: merge two arrays one as key to another php 
Php :: In PackageManifest.php line 122: 
Php :: wordpress featured image show 
Php :: how to build jquery messages notification with php and mysq 
Php :: csv to array php 
Php :: how to use postgresql with laravel 
Php :: time php 
Php :: lluminate/contracts[v5.6.0, ..., 5.8.x-dev] require php ^7.1.3 - your php version (8.0.10) does not satisfy that requirement. 
Php :: round up built in function php 
Php :: laravel check empty string 
Php :: how to get a whole number from decimal in php 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =