2017-12-10 7 views
0

Woocommerce 복합 제품 확장 (다른 제품 조합을 통해 제품을 만들 수 있음)과 함께 Woocommerce를 사용하고 있습니다.Woocommerce 복합 제품 구성 요소 가져 오기

복합 제품이 '재고 있음'인지 알아 내려고하지만, 일반적인 함수 인 is_in_stock()은 합성물에서 작동하지 않습니다.

더 적절한 기능이 있다면, 나는 그것이 무엇인지 알고 싶습니다.

$product = wc_get_product($productid); 
var_dump($product); 

반환 : 기본적으로

object(WC_Product_Composite)#11305 (23) { 
    ["extended_data":"WC_Product_Composite":private]=> 
    array(7) { 
    ["add_to_cart_form_location"]=> 
    string(7) "default" 
    ["shop_price_calc"]=> 
    string(7) "default" 
    } 
    ["composite_meta":"WC_Product_Composite":private]=> 
    array(4) { 
    [1477435352]=> 
    array(19) { 
     ["component_id"]=> 
     string(10) "1477435352" 
     ["query_type"]=> 
     string(11) "product_ids" 
     ["assigned_ids"]=> 
     array(2) { 
     [0]=> 
     int(541) 
     [1]=> 
     int(588) 
     } 
    } 
} 

, 내가 원하는 것은 추출하고

Alternatrively, 기능 'wc_get_product는()'아래 componentproduct 아이디 (assigned_ids)를 포함하여 아래의 반환 각각의 재고가있는 경우 'assigned_ids'하위 배열 검사를 반복하되 화면에 인쇄하는 것 외에도이 객체의 속성은 '비공개'(완전히 익숙하지 않음)이기 때문에이 객체의 속성에 액세스 할 수 없습니다. 나는 이것을 Wordpress/플러그인 파일에서 수업을 사냥해서 알아낼 수 있다고 생각하지만, 어떻게 찾지는 모르겠다. 어떤 도움이라도 대단히 감사 할 것입니다.

답변

0

증권(훨씬 더 복잡한 복합 제품) : 복합 제품에 주식 및 재고 관리에 관한

, 그것은이하지 않는, 그것에 대해 WC_CP_Stock_ManagerWC_CP_Stock_Manager_Item 전용 클래스입니다 분명히 있도록 "items""collections"의 개념으로 고전적인 방식으로 작동하는 것 같습니다.

이 방법과 기능은 includes/class-wc-cp-stock-manager.php 코어 파일에서 사용할 수 있습니다.


데이터 액세스 : 당신이 볼 수 있듯이

에서, WC_Product_Composite 개체 보호 특성을 얻을 수를, 당신은 핵심에 설명 된 상속 WC_Product 방법이나 더 구체적으로 WC_Product_Composite 방법을 사용해야한다 코드 클래스. 이제

, 에 액세스 할 수있는 가장 쉬운 방법는 (보호되지 않은) 데이터는 WC_Data 클래스에서 상속 다음 방법 을 사용하는 것입니다

// Get an instance of the WC_Product_Composite object 
$product = wc_get_product($product_id); 

// Get the data in an unprotected array 
$product_data = $product->get_data(); 

// Output the raw data (for test) 
echo '<pre>'; print_r($product_data); echo '</pre>'; 

// Get special meta data in an unprotected array (if it exist) 
$product_meta_data = $product->get_meta_data(); 

// Output the raw special meta data (for test) 
echo '<pre>'; print_r($product_meta_data); echo '</pre>'; 

또는 일부 WC_Product_Composite 방법으로도 사용할 수 있습니다

// Get an instance of the WC_Product_Composite object 
$product = wc_get_product($product_id); 

// Get the component Id 
$component_data = $product->get_component_id(); 

// Get the component 
$component_data = $product->get_component(); 

// Get the raw component data 
$component_data = $product->get_component_data(); 

어떤 방식 으로든 작동하는 방식을 이해하고 복합 제품에 적합한 방법을 얻으려면 코어 파일 코드로 들어가야합니다.

관련 문제