How to add metabox ONLY to specific WooCommerce product type [closed]

You should be able to get the current product id using the using the $post global variable and use that with the WooCommerce function get_product() to the the product object and test its product type. public function __construct() { add_action( ‘add_meta_boxes’, array( $this, ‘add_meta_box’ ) ); } public function add_meta_box( $post_type ) { $post_types = … Read more

MetaBox with Editor instead of textarea – html not saved [closed]

I have solved this problem after many researches, just comment two lines in meta_box.php file at end. $sanitizer = isset( $field[‘sanitizer’] ) ? $field[‘sanitizer’] : ‘sanitize_text_field’; to //$sanitizer = isset( $field[‘sanitizer’] ) ? $field[‘sanitizer’] : ‘sanitize_text_field’; at line 692 and $new = meta_box_sanitize( $new, $sanitizer ); to //$new = meta_box_sanitize( $new, $sanitizer ); at line … Read more

Global Variable vs Local Variable

As @Milo pointed out, when you use code in OP $post_types is undefined inside the function, so WordPress will act just like it was not there at all. However, that means you are using an undefined variable, and if turn WP_DEBUG on you’ll see a warning, and so you can notice you are doing something … Read more

How to remove some metaboxes for CPTs?

@Jeffrey’s answer is correct is you are the one registering the post types, simply remove the support argument for comments. But if you want to remove it from all custom post types (that may be registered by plugins too) you can do: $cptslugs = get_post_types( array(‘public’=>false, ‘_builtin’ => false) , ‘names’, ‘and’); foreach ($cptslugs as … Read more

Have mu-plugin remove meta box ONLY if it isn’t already removed in functions.php

Hmm, a lazy workaround—as long as you’re not running PHP < 5.3.0—might be to use a namespace in your mu-plugins file. Something like this might do the trick: <?php namespace Arglebargle; \add_action( ‘wp_dashboard_setup’, ‘Arglebarle\remove_x_widget’ ); function remove_x_widget() { // If the meta box has already been removed, it shouldn’t be an // issue to ‘remove’ … Read more

add_post_meta() & update_post_meta()

add_post_meta() : Adds a meta field to the given post. Below is the example, <?php $post_id = 1; $meta_key = ‘_test’; $meta_value=”this is a test”; $unique = true; add_post_meta( $post_id, $meta_key, $meta_value, $unique ); update_post_meta() : if the given key already exists among custom fields of the specified post, another custom field with the same … Read more