programing

WooCommerce - product_id별로 제품 설명을 가져옵니다.

telecom 2023. 3. 6. 20:39
반응형

WooCommerce - product_id별로 제품 설명을 가져옵니다.

제품 ID를 사용하여 제품 설명이나 제품 객체를 어떻게 얻을 수 있습니까?

$order = new WC_Order($order_id);

foreach ($order->get_items() as $item) {
    $product_description = get_the_product_description($item['product_id']); // is there any method can I use to fetch the product description?
}

위 코드는 클래스 WC_Payment_Gateway를 확장합니다.

어떤 도움이라도 주시면 감사하겠습니다.

$order = new WC_Order($order_id);

foreach ($order->get_items() as $item)
{
    $product_description = get_post($item['product_id'])->post_content; // I used wordpress built-in functions to get the product object 
}

WooCommerce를 사용하는 경우3.0그 이상이면 아래 코드로 설명을 얻을 수 있습니다.

$order = wc_get_order($order_id);

foreach ($order->get_items() as $item) {
    $product_id = $item['product_id'];
    $product_details = $product->get_data();

    $product_full_description = $product_details['description'];
    $product_short_description = $product_details['short_description'];
}

대체 방법(권장)

$order = wc_get_order($order_id);

foreach ($order->get_items() as $item) {
    $product_id = $item['product_id'];
    $product_instance = wc_get_product($product_id);

    $product_full_description = $product_instance->get_description();
    $product_short_description = $product_instance->get_short_description();
}

이게 도움이 됐으면 좋겠네요!

언급URL : https://stackoverflow.com/questions/19763915/woocommerce-get-the-product-description-by-product-id

반응형