xxxxxxxxxx
$categories_html = get_the_term_list($product->ID, 'product_cat', '', ', ');
$categories_text = strip_tags($categories_html);
echo $categories_text;
xxxxxxxxxx
$product = wc_get_product( $post_id );
$product->get_regular_price();
$product->get_sale_price();
$product->get_price();
xxxxxxxxxx
// Get Product ID
$product->get_id();
// Get Product General Info
$product->get_type();
$product->get_name();
$product->get_slug();
$product->get_date_created();
$product->get_date_modified();
$product->get_status();
$product->get_featured();
$product->get_catalog_visibility();
$product->get_description();
$product->get_short_description();
$product->get_sku();
$product->get_menu_order();
$product->get_virtual();
get_permalink( $product->get_id() );
// Get Product Prices
$product->get_price();
$product->get_regular_price();
$product->get_sale_price();
$product->get_date_on_sale_from();
$product->get_date_on_sale_to();
$product->get_total_sales();
// Get Product Tax, Shipping & Stock
$product->get_tax_status();
$product->get_tax_class();
$product->get_manage_stock();
$product->get_stock_quantity();
$product->get_stock_status();
$product->get_backorders();
$product->get_sold_individually();
$product->get_purchase_note();
$product->get_shipping_class_id();
// Get Product Dimensions
$product->get_weight();
$product->get_length();
$product->get_width();
$product->get_height();
$product->get_dimensions();
// Get Linked Products
$product->get_upsell_ids();
$product->get_cross_sell_ids();
$product->get_parent_id();
// Get Product Variations and Attributes
$product->get_children(); // get variations
$product->get_attributes();
$product->get_default_attributes();
$product->get_attribute( 'attributeid' ); //get specific attribute value
// Get Product Taxonomies
$product->get_categories();
$product->get_category_ids();
$product->get_tag_ids();
// Get Product Downloads
$product->get_downloads();
$product->get_download_expiry();
$product->get_downloadable();
$product->get_download_limit();
// Get Product Images
$product->get_image_id();
$product->get_image();
$product->get_gallery_image_ids();
// Get Product Reviews
$product->get_reviews_allowed();
$product->get_rating_counts();
$product->get_average_rating();
$product->get_review_count();
xxxxxxxxxx
// Get all product categories
$terms = get_terms(array('taxonomy' => 'product_cat', 'hide_empty' => 0));
// Loop through all product categories
foreach ($terms as $key => $value) {
// Get category name
$term_name = $value->name;
// Get category link
$term_link = get_term_link($value, 'product_cat');
// Output link and name
echo '<li><a href="' . $term_link . '">' . $term_name . '</a></li>';
}
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
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');