xxxxxxxxxx
$product = wc_get_product( $post_id );
$product->get_regular_price();
$product->get_sale_price();
$product->get_price();
xxxxxxxxxx
$product = wc_get_product($product_id);
$variations = $product->get_available_variations();
$variations_id = wp_list_pluck( $variations, 'variation_id' );
xxxxxxxxxx
$id = 42;
if( $term = get_term_by( 'id', $id, 'product_cat' ) ){
echo $term->name;
}
xxxxxxxxxx
global $product;
$koostis = $product->get_attribute( 'pa_koostis' );
xxxxxxxxxx
$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id[] = $term->term_id;
}
xxxxxxxxxx
$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);
xxxxxxxxxx
$categories_html = get_the_term_list($product->ID, 'product_cat', '', ', ');
$categories_text = strip_tags($categories_html);
echo $categories_text;
xxxxxxxxxx
syntax:- get_page_by_title( $page_title, $output, $post_type );
In wordpress 6.2 this function is deprecated
instead you can use it's definition with little bit of change
https://developer.wordpress.org/reference/functions/get_page_by_title/
function get_page_by_title(string $name, string $post_type = "post") {
$query = new WP_Query([
"post_type" => $post_type,
"name" => $name
]);
return $query->have_posts() ? reset($query->posts) : null;
}
now call get_page_by_title(<product_name>, 'product');
xxxxxxxxxx
global $product;
$koostis = array_shift( wc_get_product_terms( $product->id, 'pa_koostis', array( 'fields' => 'names' ) ) );