반응형
wo commerce in word press return 항상 단순한 제품 유형
그룹화된 제품의 종류를 구하려고 하지만 WC_Product_Factory를 사용하면 우커머스가 빈 상태로 돌아오거나 항상 "간단" 상태로 돌아옵니다.
사용할 때:
$the_product = new WC_Product(2886);
echo $the_product->product_type;
빈 채로 반환합니다.
WC_Product_Factory 사용 시:
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
항상 "simple"를 반환합니다.
다음을 사용하려고 합니다.
$the_product = wc_get_product(2886);
echo $the_product->product_type;
그러나 이것은 "Call to member function get_product()"라는 오류를 반환합니다.."
내 코드는 안에 있습니다.
add_action( 'plugins_loaded', function(){
$the_product = new WC_Product(2886);
echo $the_product->product_type;
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
$the_product = wc_get_product(2886);
echo $the_product->product_type;
die();
});
도와주셔서 감사합니다!
해결책 또는 실수를 발견했습니다. plugins_loaded to init:
add_action( 'init', function(){
$the_product = new WC_Product(2886);
echo $the_product->product_type;
$the_product = new WC_Product(2886);
$the_product_factory = new WC_Product_Factory();
$the_product = $the_product_factory->get_product($the_product);
echo $the_product->product_type;
$the_product = wc_get_product(2886);
echo $the_product->product_type;
die();
});
그리고 이 작품!
이 url https://wordpress.stackexchange.com/questions/120055/woocommerce-create-new-product-and-add-to-cart-on-form-submit 이 아이디어를 저에게 주었습니다.
해피코딩! :)
이 코드를 사용하여 사용자 지정 제품 유형을 가져올 수 있습니다.
$terms = get_the_terms($product_id, 'product_type');
$product_type = !empty($terms) ? sanitize_title(current($terms)->name) : 'simple';
언급URL : https://stackoverflow.com/questions/28355770/woocommerce-in-wordpress-return-always-simple-as-product-type
반응형
'source' 카테고리의 다른 글
도커 컨테이너 내에서 Nginx를 중단하지 않고 실행하는 방법? (0) | 2023.10.01 |
---|---|
추가 기능을 사용자 지정할 수 있도록 .ppam 파일 (0) | 2023.10.01 |
PL/SQL에 해시 함수가 있습니까? (0) | 2023.10.01 |
클래스 또는 구조 내에서 스레드 로컬 변수를 사용할 수 있습니까? (0) | 2023.10.01 |
CSS에서 자녀에게 부모의 곡선 경계선을 지키도록 강요 (0) | 2023.10.01 |