반응형
Wocommerce 백엔드 제품 편집 페이지의 제품 유형 옵션에 확인란 추가
Wocommerce admin 제품 데이터 설정에 custom option이 확인란을 활성화하고 변경 사항을 저장하면 값이 제품 메타 데이터에 올바르게 저장되지만 확인란은 선택되지 않습니다.
내가 뭘 잘못하고 있는 거지?이것을 다른 옵션 확인란으로 작동시키는 방법은?
내 코드:
function add_e_visa_product_option( $product_type_options ) {
$product_type_options[''] = array(
'id' => '_evisa',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'eVisa', 'woocommerce' ),
'description' => __( '', 'woocommerce' ),
'default' => 'no'
);
return $product_type_options;
}
add_filter( 'product_type_options', 'add_e_visa_product_option' );
function save_evisa_option_fields( $post_id ) {
$is_e_visa = isset( $_POST['_evisa'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_evisa', $is_e_visa );
}
add_action( 'woocommerce_process_product_meta_simple', 'save_evisa_option_fields' );
add_action( 'woocommerce_process_product_meta_variable', 'save_evisa_option_fields' );
답은 매우 간단합니다. 첫 번째 기능에서 어레이의 키 ID를 추가하는 것을 잊어버린 것입니다.
$product_type_options['evisa'] = array( // … …
그래서 당신의 코드에.
add_filter( 'product_type_options', 'add_e_visa_product_option' );
function add_e_visa_product_option( $product_type_options ) {
$product_type_options['evisa'] = array(
'id' => '_evisa',
'wrapper_class' => 'show_if_simple show_if_variable',
'label' => __( 'eVisa', 'woocommerce' ),
'description' => __( '', 'woocommerce' ),
'default' => 'no'
);
return $product_type_options;
}
add_action( 'woocommerce_process_product_meta_simple', 'save_evisa_option_fields' );
add_action( 'woocommerce_process_product_meta_variable', 'save_evisa_option_fields' );
function save_evisa_option_fields( $post_id ) {
$is_e_visa = isset( $_POST['_evisa'] ) ? 'yes' : 'no';
update_post_meta( $post_id, '_evisa', $is_e_visa );
}
코드가 작동합니다.활성 하위 테마(또는 활성 테마)의 php 파일입니다.테스트를 거쳐 작동합니다.
언급URL : https://stackoverflow.com/questions/50043644/add-checkbox-to-product-type-option-in-woocommerce-backend-product-edit-pages
반응형
'sourcecode' 카테고리의 다른 글
현재 암호를 모르는 경우 asp.net 멤버십 제공자를 사용하여 해시 암호를 변경하는 방법은 무엇입니까? (0) | 2023.09.26 |
---|---|
빈 테이블에서 쿼리 실행 속도가 느립니다.(많은 양의 삽입물을 삭제한 후 (0) | 2023.09.26 |
워드프레스 SQL은 X 제품에 대한 사용자의 이름과 성을 쿼리합니까? (0) | 2023.09.26 |
각2 사용자 정의 양식 입력 (0) | 2023.09.26 |
최대 청취자경고 초과: EventEmitter 메모리 누출 가능성이 감지되었습니다. 11개의 메시지 수신기가 추가되었습니다.이미터를 사용합니다.최대 청취자()를 설정하여 제한을 늘립니다. (0) | 2023.09.26 |