xxxxxxxxxx
// If the WC_product Object is not defined globally
global $product;
if ( ! is_a( $product, 'WC_Product' ) ) {
$product = wc_get_product( get_the_id() );
}
echo $product->get_name();
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
$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' ) ) );
xxxxxxxxxx
/**
*
* 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;
}
}
xxxxxxxxxx
$result = array_shift(woocommerce_get_product_terms($product->id, 'pa_koostis', 'names'));
xxxxxxxxxx
#include <vector>
2#include <algorithm>
3
4class Solution {
5public:
6 int findLengthOfShortestSubarray(std::vector<int>& arr) {
7 int n = arr.size(); // The size of the input array
8 int left = 0, right = n - 1; // Pointers to iterate through the array
9
10 // Expand the left pointer as long as the current element is smaller or equal than the next one
11 // This means the left part is non-decreasing
12 while (left + 1 < n && arr[left] <= arr[left + 1]) {
13 ++left;
14 }
15
16 // If the whole array is non-decreasing, no removal is needed
17 if (left == n - 1) {
18 return 0;
19 }
20
21 // Expand the right pointer inwards as long as the next element leftwards is smaller or equal
22 // This means the right part is non-decreasing
23 while (right > 0 && arr[right - 1] <= arr[right]) {
24 --right;
25 }
26
27 // Calculate the initial length of the subarray that we can potentially remove
28 int minSubarrayLength = std::min(n - left - 1, right);
29
30 // Attempt to merge the non-decreasing parts on the left and the right
31 for (int l = 0, r = right; l <= left; ++l) {
32 // Find the first element which is not less than arr[l] in the right part to merge
33 while (r < n && arr[r] < arr[l]) {
34 ++r;
35 }
36 // Update the answer with the minimum length after merging
37 minSubarrayLength = std::min(minSubarrayLength, r - l - 1);
38 }
39
40 // Return the answer which is the length of the shortest subarray to remove
41 return minSubarrayLength;
42 }
43};
44