WooCommerce에서 다운로드 가능한 제품 기능을 비활성화하는 방법
마켓플레이스 웹사이트에서 WooCommerce를 사용하고 있는데 "다운로드 가능한 제품" 기능을 비활성화하는 솔루션을 찾고 있습니다.주로 벤더의 백엔드에 표시되지 않는 것이 좋습니다.
Claudio Sanches(@claudiosanches) 작성자:[ WooCommerce ]> [ Settings ]> [ Account ]순서로 이동하여 다운로드 엔드포인트필드를 클리어합니다.다운로드 페이지가 비활성화됩니다.
Christophvh에 의해 이 답을 얻었어요.
[ Account endpoints ]섹션의 [Downloads]엔트리를 삭제하고 공백으로 둡니다.그리고 메뉴는 더 이상 표시되지 않습니다.첨부한 제 이미지를 보세요.
function CM_woocommerce_account_menu_items_callback($items) {
unset( $items['downloads'] );
return $items;
}
add_filter('woocommerce_account_menu_items', 'CM_woocommerce_account_menu_items_callback', 10, 1);
상기 대신 사용.
이 암호는 나에게 효과가 있었어.Woocommerce Support에서 받았습니다.https://wordpress.org/support/topic/remove-virtual-downloadable-products-selection/
function my_remove_product_type_options( $options ) {
// uncomment this if you want to remove virtual too.
// if ( isset( $options['virtual'] ) ) {
// unset( $options['virtual'] );
// }
if ( isset( $options['downloadable'] ) ) {
unset( $options['downloadable'] );
}
return $options;
}
add_filter( 'product_type_options', 'my_remove_product_type_options' );
제대로 이해했는지 모르겠지만, "내 계정" 페이지에서 "다운로드" 네비게이션 옵션을 삭제할 의향이 있다면 다음을 계속 읽으십시오.
- 현재 사용 중인 테마에 맞게 하위 테마를 만듭니다.자세한 내용을 모르는 경우 https://codex.wordpress.org/Child_Themes를 참조하십시오.
- 이제 네비게이션을 복사합니다.php from...\wp-content\plugins\woocommerce\templates\myaccounts\child Theme 폴더에...\wp-content\yourteme-child\woocommerce\myaccount\
- 네비게이션을 엽니다.php를 Child 테마 폴더에 저장합니다.wc_get_account_menu_items() 함수의 행을 찾고 함수 이름을 wc_get_account_menu_items_custom()과 같이 변경합니다.
함수를 엽니다.php를 Child 테마 폴더에 저장합니다.아래 파일 안에 붙여넣기 기능.파일을 저장하기만 하면 됩니다.이제 "내 계정" 페이지에 "다운로드" 탐색 옵션이 없습니다.
function wc_get_account_menu_items_custom() { $endpoints = array( 'orders' => get_option( 'woocommerce_myaccount_orders_endpoint', 'orders' ), 'edit-address' => get_option( 'woocommerce_myaccount_edit_address_endpoint', 'edit-address' ), 'payment-methods' => get_option( 'woocommerce_myaccount_payment_methods_endpoint', 'payment-methods' ), 'edit-account' => get_option( 'woocommerce_myaccount_edit_account_endpoint', 'edit-account' ), 'customer-logout' => get_option( 'woocommerce_logout_endpoint', 'customer-logout' ), ); $items = array( 'dashboard' => __( 'Dashboard', 'woocommerce' ), 'orders' => __( 'Orders', 'woocommerce' ), 'edit-address' => __( 'Addresses', 'woocommerce' ), 'payment-methods' => __( 'Payment Methods', 'woocommerce' ), 'edit-account' => __( 'Account Details', 'woocommerce' ), 'customer-logout' => __( 'Logout', 'woocommerce' ), ); // Remove missing endpoints. foreach ( $endpoints as $endpoint_id => $endpoint ) { if ( empty( $endpoint ) ) { unset( $items[ $endpoint_id ] ); } } // Check if payment gateways support add new payment methods. if ( isset( $items['payment-methods'] ) ) { $support_payment_methods = false; foreach ( WC()->payment_gateways->get_available_payment_gateways() as $gateway ) { if ( $gateway->supports( 'add_payment_method' ) || $gateway->supports( 'tokenization' ) ) { $support_payment_methods = true; break; } } if ( ! $support_payment_methods ) { unset( $items['payment-methods'] ); } } return apply_filters( 'woocommerce_account_menu_items_custom', $items ); }주의: 이것은 원래 WooCommerce 기능을 편집한 것입니다."Downloads" 옵션을 언급하는 삭제된 어레이 필드가 있습니다.이게 도움이 됐으면 좋겠다.
위의 모든 답변을 바탕으로 다음 기능을 비활성화하는 "올인원" 솔루션을 구축했습니다.
- 다운로드 엔드포인트
- 관리자 제품 편집기의 확인란 옵션입니다.
- 제품 유형 필터의 드롭다운 옵션.
- 는 주문에서 메타박스를 다운로드합니다.
파일: class-disablewoocommerce product types.php
class DisableWooCommerceProductTypes {
/**
* @var array Product types in this property will be disabled.
*/
public $disabled = [
'virtual',
'downloadable'
];
/**
* @var array WooCommerce uses different references for the same product types.
*/
private $aliases = [
'downloadable' => [ 'downloads' ]
];
/**
* @var int The priority of these overrides.
*/
public $priority = PHP_INT_MAX;
/**
* @var null|string|array $product_types Accepts a string or array of 'virtual' and/or 'downloadable' product types.
*/
public function __construct( $product_types = null ) {
if ( $product_types ) {
$this->disabled = (array)$product_types;
}
add_filter( 'product_type_options', [ $this, 'disable_admin_options' ], $this->priority );
add_filter( 'woocommerce_account_menu_items', [ $this, 'disable_frontend_nav_items' ], $this->priority );
add_filter( 'add_meta_boxes', [ $this, 'disable_admin_metabox' ], $this->priority );
add_filter( 'woocommerce_products_admin_list_table_filters', [ $this, 'disable_admin_filters' ], $this->priority );
// Disable the downloads endpoint
if ( $this->is_disabled( 'downloadable' ) ) {
add_filter( 'default_option_woocommerce_myaccount_downloads_endpoint', '__return_null' );
add_filter( 'option_woocommerce_myaccount_downloads_endpoint', '__return_null' );
}
}
/**
* Quickly check if a product type is disabled. Returns primary key if $type is an alias and disabled.
*
* @param string $type
* @param bool $aliases Check for aliases.
* @return bool|string
*/
private function is_disabled( string $type, bool $aliases = true ) {
$basic_check = in_array( $type, $this->disabled );
if ( $aliases && !$basic_check ) {
foreach ( $this->aliases as $_type => $_aliases ) {
if ( in_array( $type, $_aliases ) && $this->is_disabled( $_type, false ) ) {
return $_type;
}
}
}
return $basic_check;
}
/**
* Remove product type checkboxes from product editor.
*
* @param array $types
* @return array
*/
public function disable_admin_options( $types ) {
foreach ( $types as $key => $value ) {
if ( $this->is_disabled( $key ) ) {
unset( $types[ $key ] );
}
}
return $types;
}
/**
* Removes product type page from `wc_get_account_menu_items()`
*
* @param array $items
* @return array
*/
public function disable_frontend_nav_items( $items ) {
foreach ( $items as $key => $value ) {
if ( $this->is_disabled( $key ) ) {
unset( $items[ $key ] );
}
}
return $items;
}
/**
* Removes the downloads metabox from orders.
*/
public function disable_admin_metabox() {
if ( $this->is_disabled( 'downloadable' ) ) {
remove_meta_box( 'woocommerce-order-downloads', 'shop_order', 'normal' );
}
}
/**
* Add our admin product table filter modifier.
*
* @param array $filters
* @return array
*/
public function disable_admin_filters( $filters ) {
if ( isset( $filters[ 'product_type' ] ) ) {
$filters[ 'product_type' ] = [ $this, 'disable_product_type_filters' ];
}
return $filters;
}
/**
* Remove disabled product types from the admin products table filters.
*/
public function disable_product_type_filters() {
$current_product_type = isset( $_REQUEST['product_type'] ) ? wc_clean( wp_unslash( $_REQUEST['product_type'] ) ) : false; // WPCS: input var ok, sanitization ok.
$output = '<select name="product_type" id="dropdown_product_type"><option value="">' . esc_html__( 'Filter by product type', 'woocommerce' ) . '</option>';
foreach ( wc_get_product_types() as $value => $label ) {
$output .= '<option value="' . esc_attr( $value ) . '" ';
$output .= selected( $value, $current_product_type, false );
$output .= '>' . esc_html( $label ) . '</option>';
if ( 'simple' === $value ) {
if ( !$this->is_disabled( 'downloadable' ) ) {
$output .= '<option value="downloadable" ';
$output .= selected( 'downloadable', $current_product_type, false );
$output .= '> ' . ( is_rtl() ? '←' : '→' ) . ' ' . esc_html__( 'Downloadable', 'woocommerce' ) . '</option>';
}
if ( !$this->is_disabled( 'virtual' ) ) {
$output .= '<option value="virtual" ';
$output .= selected( 'virtual', $current_product_type, false );
$output .= '> ' . ( is_rtl() ? '←' : '→' ) . ' ' . esc_html__( 'Virtual', 'woocommerce' ) . '</option>';
}
}
}
$output .= '</select>';
echo $output; // WPCS: XSS ok.
}
}
파일: 함수.php
include_once get_theme_file_path( 'path/to/class-disablewoocommerceproducttypes.php' );
new DisableWooCommerceProductTypes();
에서는, 모두가 .downloadable ★★★★★★★★★★★★★★★★★」virtual제품 유형.
단일 제품 유형을 비활성화하려면 해당 유형을 클래스 생성자에게 전달하기만 하면 됩니다.
// Example usage for just `downloadable` product type
new DisableWooCommerceProductTypes( 'downloadable' );
// Example usage for just `virtual` product type
new DisableWooCommerceProductTypes( 'virtual' );
기능을 완전히 삭제하려면 몇 가지 추가 단계가 있습니다.
모두 확인:
Osmar Sanches 및 MD Ashik 응답에 따라 WooCommerce > Settings > Advanced > Downloads에서 엔드포인트를 클리어합니다.
Maher Aldous 답변에 따라 필터를 추가합니다.
Misha Rudrasyth의 블로그 투고에 따라 "제품 유형 필터에서 드롭다운 옵션"을 제거합니다.
add_filter( 'woocommerce_products_admin_list_table_filters', function( $filters ) { if( isset( $filters[ 'product_type' ] ) ) { $filters[ 'product_type' ] = 'misha_product_type_callback'; } return $filters; }); function misha_product_type_callback(){ $current_product_type = isset( $_REQUEST['product_type'] ) ? wc_clean( wp_unslash( $_REQUEST['product_type'] ) ) : false; $output = '<select name="product_type" id="dropdown_product_type"><option value="">Filter by product type</option>'; foreach ( wc_get_product_types() as $value => $label ) { $output .= '<option value="' . esc_attr( $value ) . '" '; $output .= selected( $value, $current_product_type, false ); $output .= '>' . esc_html( $label ) . '</option>'; } $output .= '</select>'; echo $output; }주문(편집 및 신규)에서 메타박스 "다운로드 가능한 제품 권한"을 제거합니다.
add_filter('add_meta_boxes', function() { remove_meta_box('woocommerce-order-downloads', 'shop_order', 'normal'); }, 99 );
CSS 수정...기능을 조작할 수 없습니다.
.woocommerce-MyAccount-navigation-link--downloads {
display: none;
}
똑같은 문제가 있어서 그냥 고쳤어.
다음과 같이 합니다.
...\www\되어 있습니다your_folder\wp-content\plugins\woocommerce\
여기서 wc_get_account_menu_menu() 함수를 검색합니다(78행).
이제 이 라인(라인 91)을 바꿉니다.
'downloads' => __( 'Downloads', 'woocommerce' ),
이것으로
/* 'downloads' => __( 'Downloads', 'woocommerce' ),*/
바로 그겁니다.
언급URL : https://stackoverflow.com/questions/38666414/how-to-disable-downloadable-product-functionality-in-woocommerce
'source' 카테고리의 다른 글
| 유형 스크립트로 반응 - React.forwardRef 사용 시 일반 정보 (0) | 2023.03.16 |
|---|---|
| 공급자가 Oracle 클라이언트 버전과 호환되지 않습니다. (0) | 2023.03.16 |
| Java Spring Boot Test: 테스트 컨텍스트에서 Java 컨피규레이션클래스를 제외하는 방법 (0) | 2023.03.16 |
| 개체를 파괴하고 결과 중 하나를 무시하는 중 (0) | 2023.03.16 |
| --disable-web-security는 Chrome에서 동작하게 되었습니까? (0) | 2023.03.16 |
