I want to remove some meta boxes like:
Product Short description,
Reviews
I can remove default metaboxes:
function remove_metaboxes() {
remove_meta_box( 'postcustom' , 'product' , 'normal' );
remove_meta_box( 'postexcerpt' , 'product' , 'normal' );
remove_meta_box( 'commentsdiv' , 'product' , 'normal' );
remove_meta_box( 'tagsdiv-product_tag' , 'product' , 'normal' );
}
add_action( 'admin_menu' , 'remove_metaboxes' );
But I cant remove "postexcerpt" - Product Short description and "commentsdiv" - Reviews, because they are loaded in add_filter - add_meta_boxes
Is there any other hook after this to apply my script ? Or maybe there is another method ?
Thank you!
WooCommerce removes the default postexcerpts and replaces it with its own version (the 'Product Short Description' meta box) (class-wc-admin-meta-boxes.php)
So like user1139767 said, you have to alter the priority. However when I tried 11, it didn't work, neither did 20. But 50 seems to do the trick:
function remove_metaboxes() {
remove_meta_box( 'postcustom' , 'product' , 'normal' );
remove_meta_box( 'postexcerpt' , 'product' , 'normal' );
remove_meta_box( 'commentsdiv' , 'product' , 'normal' );
remove_meta_box( 'tagsdiv-product_tag' , 'product' , 'normal' );
}
add_action( 'add_meta_boxes' , 'remove_metaboxes', 50 );
function remove_my_metaboxes() {
remove_meta_box( 'categorydiv','post','normal' ); // Categories Metabox
remove_meta_box( 'submitdiv','post','normal' ); // Categories Metabox
remove_meta_box( 'postcustom','page','normal' ); // Custom Fields Metabox
remove_meta_box( 'postcustom','post','normal' ); // Custom Fields Metabox
remove_meta_box( 'commentstatusdiv','page','normal' ); // Comments Metabox
remove_meta_box( 'commentsdiv','post','normal' ); // Comments Metabox
remove_meta_box( 'trackbacksdiv','page','normal' ); // Talkback Metabox
remove_meta_box( 'trackbacksdiv','post','normal' ); // Trackback Metabox
remove_meta_box( 'authordiv','page','normal' ); // Author Metabox
remove_meta_box( 'authordiv','post','normal' ); // Author Metabox
remove_meta_box( 'postexcerpt','post','normal' ); // Excerpt Metabox
remove_meta_box( 'postexcerpt','page','normal' ); // Excerpt Metabox
remove_meta_box( 'revisionsdiv','post','normal' ); // Revisions Metabox
remove_meta_box( 'slugdiv','page','normal' ); // Slug Metabox
remove_meta_box( 'slugdiv','post','normal' ); // Slug Metabox
remove_meta_box( 'formatdiv','post','normal' ); // Formats Metabox
remove_meta_box( 'postimagediv','post','normal' ); // Featured Image Metabox
remove_meta_box( 'tagsdiv-post_tag','post','normal' ); // Tags Metabox
remove_meta_box( 'commentstatusdiv','post','normal' ); // Comments Status Metabox
}
add_action('admin_menu','remove_my_metaboxes');
just comment out "remove_meta_box" what you want to display in your page/posts.
Also we able to remove the meta boxes by changing on your custom post types name into the remove_meta_box function instead of "post" or "page".
remove_meta_box( 'tagsdiv-product_tag' , 'product' , 'normal' );
isn't correct, use instead :
remove_meta_box( 'tagsdiv-product_tag','product','side' );
to remove the box 'keywords product'
just added priority to add_action:
add_action( 'add_meta_boxes' , 'remove_metaboxes', 11 );
The default priority is 10, so I added 11 to make action after 10.
To remove WooCommerce product categories metabox, add this to functions.php:
add_action('add_meta_boxes_product', 'bbloomer_remove_metaboxes_edit_product', 9999);
function bbloomer_remove_metaboxes_edit_product()
{
// e.g. Remove WooCommerce product categories metabox
remove_meta_box('product_catdiv', 'product', 'normal');
}
I spent hours on this to remove the WooCommerce short description metabox (and then add it up above the main content editor). I could ONLY get rid of the postexcerpt by using the add_meta_boxes hook. admin_menu and adminhead ran too early. So I removed everything else at the same time.
function WH_remove_meta_boxes() {
remove_meta_box( 'postexcerpt', 'product', 'normal' );
remove_meta_box( 'tagsdiv-product_tag', 'product', 'side' );
remove_meta_box( 'tagsdiv-yith_shop_vendor', 'product', 'side' );
remove_meta_box( 'tagsdiv-product_tag', 'product', 'side' );
remove_meta_box( 'wpseo_meta', 'product', 'normal');
}
add_action( 'add_meta_boxes', 'WH_remove_meta_boxes', 99 );
Related
Actually, I'm working on woocommerce customization...
I've read this question about the title change in metabox:
Customizing WooCommerce Short Description Metabox title
It help me a lot. But, in the product, how can I find the "metabox tag" callback name?
function epptm_rename_meta_boxes(){
remove_meta_box( 'tagsdiv-product_tag', 'product', 'side' );
add_meta_box( 'tagsdiv-product_tag', __( 'This metabox is awesome', 'your-plugin' ), 'CALLBACK?', 'product', 'side' );
}
add_action( 'add_meta_boxes', 'epptm_rename_meta_boxes', 40 );
here is another solution found:
/**
* hook to the 'add_meta_boxes' action to modify title
*/
function change_meta_box_titles() {
global $wp_meta_boxes; // array of defined meta boxes
// cycle through the array, change the titles you want
$wp_meta_boxes['product']['side']['core']['tagsdiv-product_tag']['title']= 'Here is my new title';
}
add_action('add_meta_boxes', 'change_meta_box_titles');
i am looking for a way to activate a plugin from a woocommerce single product page, the plugin displays shipping countdown for delivery but its not relevant to all products and i would like to use a check box inside the single product to turn on and of per product page
the plugin is being activated across all products at the moment using the add action from theme mod to be able to change the position this really is not necessary so if need this could be removed and replaced with some other way on activating the plugin on a per product basis
$scfwc_render_location = get_theme_mod( 'scfwc_render_location');
switch ( $scfwc_render_location ) :
case 'scfwc_after_heading' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 6 );
break;
case 'scfwc_after_price' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 11 );
break;
case 'scfwc_after_short_desc' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 21 );
break;
case 'scfwc_after_add_cart' :
add_action( 'woocommerce_single_product_summary', array( $this, 'scfwc_html_product' ), 31 );
break;
case 'scfwc_after_single_product_summary' :
add_action( 'woocommerce_product_thumbnails', array( $this, 'scfwc_html_product' ), 30 );
break;
endswitch;
I don't know what class $this is referencing, or how to get an instance of it, so this is pseudo-code. But once you have the meta field displaying and saving in the admin, you can use the meta field's value to conditionally add the scfwc_html_product() method.
function kia_conditionally_add_countdown() {
global $product;
if( $product->get_meta( '_show_countdown', true ) ) {
$my_class = somehow_get_instance_of_class();
add_action( 'woocommerce_single_product_summary', array( $my_class, 'scfwc_html_product' ), 11 );
}
}
add_action( 'woocommerce_before_single_product_summary', 'kia_conditionally_add_countdown' );
This doesn't take into account the theme mod and just hard-codes the priority/position. You could add support for the theme_mod inside the conditional logic, if needed.
How to set Catalog visibility hidden in woo-commerce WordPress programmatically?
Like its mentioned here :
https://docs.woothemes.com/document/catalog-visibility-options/
But i can't find any hook or hack, that how to do it in PHP.
I have tried doing this for some days, and there is nothing about it online so I read the woocommerce documentation and discovered that in woocommerce 3.x.x the visibility is a taxonomy called "product_visibility".
To achieve that you should set taxonomy terms, for example:
//Set product hidden:
$terms = array( 'exclude-from-catalog', 'exclude-from-search' );
wp_set_object_terms( $post_id, $terms, 'product_visibility' );
//Set product visible in catalog:
$terms = 'exclude-from-search';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );
//Set product visible in search:
$terms = 'exclude-from-catalog';
wp_set_object_terms( $post_id, $terms, 'product_visibility' );
All possible taxonomy terms:
"exclude-from-catalog"
"exclude-from-search"
"featured"
"outofstock"
The visibility is set in the custom field _visibility. You can change it with update_post_meta():
update_post_meta( $product_id, '_visibility', '_visibility_hidden' );
Possible values:
visible (Catalog & Search)
catalog (Catalog only)
search (Search only)
hidden (nowhere)
I'm working on a plugin and I'm trying to:
1- move the publish metabox from side to the bottom of the page in the normal section.
2- force 1 column layout for the plugin custom post type edit page.
3- remove the screen options tab for the custom post type.
I'm using the next code block but it dont work:
function sds_do_meta_boxes() {
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'core' );
}
add_action('do_meta_boxes', 'sds_do_meta_boxes');
function SDS_init() { //The current user is already authenticated by this time
add_filter( 'screen_layout_columns', 'so_screen_layout_columns' );
add_filter( 'get_user_option_screen_layout_dashboard', 'so_screen_layout_dashboard' );
add_filter( 'screen_options_show_screen', 'SDS_remove_screen_options_tab');
}
add_action( 'init', 'SDS_init' );
function so_screen_layout_columns( $columns ) {
$columns['dashboard'] = 1;
return $columns;
}
function so_screen_layout_dashboard() {
return 1;
}
function SDS_remove_screen_options_tab() {
return false;
}
So, the 'publish' metabox is removed but it is not re-added. Also, the 1 column layout filters don't work. I need help:)
Changing the $priority parameter from core to high and setting priority of add_action to 0 should do the trick. I would also suggest using the dynamic add_meta_boxes_{$post_type} hook:
add_action( 'add_meta_boxes_sliding_panel', 'sds_do_meta_boxes', 0, 1 );
function sds_do_meta_boxes( $post )
{
remove_meta_box( 'submitdiv', 'sliding_panel', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sliding_panel', 'normal', 'high', null );
}
I'm creating different custom post types and taxonomies and I want to remove the 'Post Tags' taxonomy from the default 'Posts' post type. How do I go about doing this?
Thanks.
I suggest you don't mess with the actual global. Its safer to simply deregister the taxonomy from the post type: register_taxonomy is used for both creation and modification.
function ev_unregister_taxonomy(){
register_taxonomy('post_tag', array());
}
add_action('init', 'ev_unregister_taxonomy');
To remove the sidebar menu entry:
// Remove menu
function remove_menus(){
remove_menu_page('edit-tags.php?taxonomy=post_tag'); // Post tags
}
add_action( 'admin_menu', 'remove_menus' );
Perhaps a more technically correct method would be to use unregister_taxonomy_for_object_type
add_action( 'init', 'unregister_tags' );
function unregister_tags() {
unregister_taxonomy_for_object_type( 'post_tag', 'post' );
}
Where it says 'taxonomy_to_remove' is where you'll enter the taxonomy you want to remove. For instance you can replace it with the existing, post_tag or category.
add_action( 'init', 'unregister_taxonomy');
function unregister_taxonomy(){
global $wp_taxonomies;
$taxonomy = 'taxonomy_to_remove';
if ( taxonomy_exists( $taxonomy))
unset( $wp_taxonomies[$taxonomy]);
}
Total unregister and remove (minimal PHP version 5.4!)
add_action('init', function(){
global $wp_taxonomies;
unregister_taxonomy_for_object_type( 'category', 'post' );
unregister_taxonomy_for_object_type( 'post_tag', 'post' );
if ( taxonomy_exists( 'category'))
unset( $wp_taxonomies['category']);
if ( taxonomy_exists( 'post_tag'))
unset( $wp_taxonomies['post_tag']);
unregister_taxonomy('category');
unregister_taxonomy('post_tag');
});
There is new function to remove taxonomy from WordPress.
Use unregister_taxonomy( string $taxonomy ) function
See details: https://developer.wordpress.org/reference/functions/unregister_taxonomy/
Use it in 'admin_init' hook insetead not 'init'
function unregister_taxonomy(){
register_taxonomy('post_tag', array());
}
add_action('admin_init', 'unregister_taxonomy');
add_action('admin_menu', 'remove_menu_items');
function remove_menu_items() {
remove_submenu_page('edit.php','edit-tags.php?taxonomy=post_tag');
}