반응형
Woocommerce 카트에서 각 제품의 작성자 ID를 가져옵니다.
woocommerce에서는 카트 내의 각 제품의 사용자 ID를 취득할 필요가 있습니다.사용자 ID는 고객으로부터의 것이 아니라 현재 장바구니에 있는 제품을 작성 및 게시한 사용자입니다(작성자 포스트).
내가 받은 코드는 다음과 같습니다.WooCommerce 플러그인에서 결제 전 주문 제품 세부 정보 가져오기
코드 공유자: @Loic TheAztec
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
$product_id = $cart_item['product_id']; // Product ID
$product_obj = wc_get_product($product_id); // Product Object
$product_qty = $cart_item['quantity']; // Product quantity
$product_price = $cart_item['data']->price; // Product price
$product_total_stock = $cart_item['data']->total_stock; // Product stock
$product_type = $cart_item['data']->product_type; // Product type
$product_name = $cart_item['data']->post->post_title; // Product Title (Name)
$product_slug = $cart_item['data']->post->post_name; // Product Slug
$product_description = $cart_item['data']->post->post_content; // Product description
$product_excerpt = $cart_item['data']->post->post_excerpt; // Product short description
$product_post_type = $cart_item['data']->post->post_type; // Product post type
$cart_line_total = $cart_item['line_total']; // Cart item line total
$cart_line_tax = $cart_item['line_tax']; // Cart item line tax total
$cart_line_subtotal = $cart_item['line_subtotal']; // Cart item line subtotal
$cart_line_subtotal_tax = $cart_item['line_subtotal_tax']; // Cart item line tax subtotal
// variable products
$variation_id = $cart_item['variation_id']; // Product Variation ID
if($variation_id != 0){
$product_variation_obj = wc_get_product($variation_id); // Product variation Object
$variation_array = $cart_item['variation']; // variation attributes + values
}
}
완벽하지만 포스트 작성자 신분증도 받아야 합니다.
어떤 도움이라도 감사합니다.
제품(카트 항목)에서 게시 작성자를 얻으려면 다음을 수행하십시오.
// For all Woocommerce versions
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
$post_obj = get_post( $cart_item['product_id'] ); // The WP_Post object
$post_author = $post_obj->post_author; // <=== The post author ID
}
Woocommerce 버전 3+와 호환되지 않아 문의 링크된 답변을 업데이트했습니다.
버전 3 이전의 Woocommerce(예를 들어 2.6.x)의 경우는, 다음을 사용할 수 있습니다.
foreach( WC()->cart->get_cart() as $cart_item_key => $cart_item ){
$authror_id = $cart_item['data']->post->post_author; // <=== The post author ID
}
언급URL : https://stackoverflow.com/questions/50461796/get-the-author-id-of-each-product-in-woocommerce-cart
반응형
'programing' 카테고리의 다른 글
Angular2 TypeScript 파일과 JavaScript 파일을 다른 폴더로 분리('dist') (0) | 2023.03.02 |
---|---|
대응: useEffect vs useMemo vs useState (0) | 2023.03.02 |
ajax 함수로 호출된 파일에 대한 직접 액세스 방지 (0) | 2023.03.02 |
Javascript로 로드된 iframe에서 HTTP 상태 코드 검색 (0) | 2023.03.02 |
Wordpress 호스트 IP가 변경되었습니다. (0) | 2023.03.02 |