I want to remove the editor and set up only the excerpt to a custom product type (WooCommerce) in my theme, is this possible?
This is how i add my custom product type to the WooCommerce product type selector
<?php
defined('ABSPATH') || exit;
class Custom_Product_Type(){
public function __construct() {
add_filter('product_type_selector', array($this, 'product_type_selector'));
}
function product_type_selector($types) {
$types['custom_product_type'] = 'Custom product type';
return $types;
}
}
new Custom_Product_Type();
I want to remove the editor and set up only the excerpt to a custom product type (WooCommerce) in my theme, is this possible?
This is how i add my custom product type to the WooCommerce product type selector
<?php
defined('ABSPATH') || exit;
class Custom_Product_Type(){
public function __construct() {
add_filter('product_type_selector', array($this, 'product_type_selector'));
}
function product_type_selector($types) {
$types['custom_product_type'] = 'Custom product type';
return $types;
}
}
new Custom_Product_Type();
Share
Improve this question
edited May 21, 2019 at 17:29
Rodrigo Butzke
asked May 21, 2019 at 15:09
Rodrigo ButzkeRodrigo Butzke
17513 bronze badges
9
- What's a "custom product type"? – Jacob Peattie Commented May 21, 2019 at 15:19
- Product type from WooCommerce, I edited the text to inform that is from WooCommerce – Rodrigo Butzke Commented May 21, 2019 at 15:22
- What, like Simple or Variable? – Jacob Peattie Commented May 21, 2019 at 15:24
- Yes, but a custom product type created from another plugin – Rodrigo Butzke Commented May 21, 2019 at 15:26
- how did you registered your custom product type… Could you share some code in your question please? without that your question is just too vague and unclear. – LoicTheAztec Commented May 21, 2019 at 16:24
2 Answers
Reset to default 1Yes, You can disable the default editor by removing 'editor' from the supports attribute array for register_post_type( 'product', $args )
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields' ),
Change this to somthing like this
'supports' => array( 'title', 'thumbnail', 'comments', 'custom-fields' ),
You can read wordpress function reference for register_post_type to learn more about custom post type arguments.
Update:
Method 1:
To change register_post_type args via "register_post_type_args" filter hook.
add_filter( 'register_post_type_args', 'product_support_args', 10, 2 );
function product_support_args( $args, $post_type ){
$post_ids_array = array(2119, 2050); // Add Your Allowed Post IDs Here
if ( 'product' === $post_type && is_admin()){
$post_id = $_GET['post']; // Get Post ID from URL
// Check if the post ID is whitelisted
if(in_array($post_id, $post_ids_array)){
$args['supports'] = array( 'title', 'thumbnail', 'comments', 'custom-fields' ); // Remove Editor from supports args array
}
}
return $args;
}
Method 2:
By using remove_post_type_support() function. You can pass allowed post ids array in the same way we did above if required.
add_action( 'current_screen', 'remove_editor_support' );
function remove_editor_support() {
$get_screen = get_current_screen();
$current_screen = $get_screen->post_type;
$post_type = 'product'; // change post type here
if ($current_screen == $post_type ) {
remove_post_type_support( $current_screen, 'editor' ); // remove editor from support argument
}
}
I've figured how to hide the editor only when the product type is selected because if i remove the support:
1) The product type is the hidden and then change the product type to another the editor doesn't appear back
2) The product type is not the hidden and then change the product type to hidden the editor dont dissappear
function admin_footer() {
if ( 'product' !== get_post_type() ) :
return;
endif;
?><script type='text/javascript'>
jQuery( document ).ready( function() {
$("#postdivrich").addClass('hide_if_custom_product_type');
$("#product-type").trigger('change');
});
</script><?php
}
add_action( 'admin_footer', array($this, 'admin_footer'));
This way, every time it selects or deselects the product type, it will hide or show using WooCommerce methods
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745475647a4629334.html
评论列表(0条)