Custom meta box not showing on WC Memberships Plan

I’m trying to add a custom meta box that will appear on Woocommerce Memberships plan posts. I’ve followed the example code using add_meta_box, but the box does not appear, either when editing a membership plan or creating a new one. It does not show in screen options either. Here is my code:

class WC_Memberships_Mailchimp_Status_Sync {
/**
* Construct the plugin.
*/
public function __construct() {
add_action( ‘plugins_loaded’, array( $this, ‘init’ ) );
}
/**
* Initialize the plugin.
*/
public function init() {
// Hook to add membership plan meta box
add_action(‘add_meta_boxes’, array($this, ‘add_membership_plan_meta_box’));
}

public function add_membership_plan_meta_box() {
add_meta_box(
“mailchimp-status-integration”,
esc_html__(“Mailchimp status sync”),
array($this, ‘sync_meta_box_content’),
“wc_membership_plan”,
“normal”,
“core”
);
}

public function sync_meta_box_content( $object ) {
echo ‘Testing.’;
}
}
$WC_Memberships_Mailchimp_Status_Sync_Plugin = new WC_Memberships_Mailchimp_Status_Sync( __FILE__ );

I know the code is all running. When I add an echo statement in the add_membership_plan_meta_box function, it shows in the admin panel. Furthermore, I’ve even tried dumping the $wp_meta_boxes variable, and I see my meta box listed in there, like so:

array(1) {
[“wc_membership_plan”]=>
array(1) {
[“normal”]=>
array(1) {
[“core”]=>
array(1) {
[“mailchimp-status-integration”]=>
array(4) {
[“id”]=>
string(28) “mailchimp-status-integration”
[“title”]=>
string(21) “Mailchimp status sync”
[“callback”]=>
array(2) {
[0]=>
object(WC_Memberships_Mailchimp_Status_Sync)#623 (0) {
}
[1]=>
string(21) “sync_meta_box_content”
}
[“args”]=>
NULL
}
}
}
}
}

But it simply doesn’t show on the editor page. I’ve tried all different combinations of the last two arguments. For the callback, I’ve tried the object-style callback seen in the example code, as well as non-object style function references and an anonymous function. I’ve also tried hooking admin_init instead of add_meta_boxes, though as I said my function to add the box is being called.

At this point, I’m wondering if WC Memberships does something funky with meta boxes that’s preventing mine from showing. It’s possible I’m making a stupid mistake or missing something obvious, but I don’t think so.

Read more here:: Custom meta box not showing on WC Memberships Plan

Leave a Reply

Your email address will not be published. Required fields are marked *