반응형
WooCommerce에서 사용자 정의 제품 유형에 대한 가격 및 재고 활성화 방법
WooCommerce 응용 프로그램에서 사용자 지정 제품 유형을 만들었습니다.
function register_variable_bulk_product_type() {
class WC_Product_Variable_bulk extends WC_Product_Simple {
public function __construct($product) {
$this->product_type = 'variable_bulk';
parent::__construct($product);
}
}
}
add_action('init', 'register_variable_bulk_product_type');
function add_variable_bulk_product($types) {
$types['variable_bulk'] = __('Variable Bulk');
return $types;
}
add_filter('product_type_selector', 'add_variable_bulk_product');
제품 데이터 드롭다운에 제품 종류를 표시하면 다음과 같습니다.
저의 고민은.
신제품은 재고와 가격을 추가할 수 있는 옵션이 없는데, 이 옵션을 활성화하려면 어떻게 해야 하나요?
가격 및 인벤토리 탭을 표시하려면 작은 JS 트릭이 필요합니다. 즉 클래스를 추가해야 합니다.
show_if_{your_custom_product_type}
당신의 경우는 그럴 것입니다.show_if_variable_bulk
.
작업 코드는 다음과 같습니다.
function wh_variable_bulk_admin_custom_js() {
if ('product' != get_post_type()) :
return;
endif;
?>
<script type='text/javascript'>
jQuery(document).ready(function () {
//for Price tab
jQuery('.product_data_tabs .general_tab').addClass('show_if_variable_bulk').show();
jQuery('#general_product_data .pricing').addClass('show_if_variable_bulk').show();
//for Inventory tab
jQuery('.inventory_options').addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._manage_stock_field').addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._sold_individually_field').parent().addClass('show_if_variable_bulk').show();
jQuery('#inventory_product_data ._sold_individually_field').addClass('show_if_variable_bulk').show();
});
</script>
<?php
}
add_action('admin_footer', 'wh_variable_bulk_admin_custom_js');
코드가 들어갑니다.functions.php
활성 하위 테마(또는 테마)의 파일입니다.또는 플러그인 PHP 파일에서도 마찬가지입니다.
코드를 테스트하고 작동합니다.
일반 탭의 모양은 다음과 같습니다.
인벤토리 탭은 이렇게 표시됩니다.
도움이 되길 바랍니다!
언급URL : https://stackoverflow.com/questions/43109755/how-to-enable-price-and-inventory-for-custom-product-type-in-woocommerce
반응형
'programing' 카테고리의 다른 글
Chrome 버전 58의 리액터 편집기 텍스트 형식 문제 (0) | 2023.10.10 |
---|---|
PHP - 특정 배열 값 카운트 (0) | 2023.10.10 |
포커스할 때 각도 ui type ahead 트리거하는 방법 (0) | 2023.10.10 |
각4 재질 테이블 하이라이트 행 (0) | 2023.10.10 |
aJAX 호출에서 html 리턴 안에 jQuery 함수 호출 (0) | 2023.10.10 |