• Resolved daymobrew

    (@daymobrew)


    My site has WooCommerce with HPOS enabled so the metabox object_type is ‘woocommerce_page_wc-order‘ (with url admin.php). In non-HPOS it would be shop_order and the url would include post.php.

    The metabox shows but the ‘cmb2_override_meta_value‘ filter is not run. I am going to use this to retrieve the data from another table.

    Similarly ‘cmb2_override_meta_save‘ does not appear to run when the WooCommerce order is saved.

    • This topic was modified 1 year, 3 months ago by daymobrew.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter daymobrew

    (@daymobrew)

    I’ve been going through the includes/CMB2_Hookup.php code. I can see that save_post() is not being called. Looking through the WooCommerce code maybe ‘woocommerce_process_shop_order_meta’ needs to be hooked to.

    add_action( 'woocommerce_process_shop_order_meta', array( $this, 'save_post' ), 10, 2 );

    Adding this helps a lot! can_save() gets run though $type is not set so it fails. It’s not set because save_post() cannot determine the post type.

    I could use the ‘cmb2_can_save‘ filter to override can_save()’s false result but that seems risky.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    This still being an issue?

    Thread Starter daymobrew

    (@daymobrew)

    Yes, still an issue.

    CMB2_Hookup::save_post() and CMB2_Hookup::can_save() are being run on save but not the ‘cmb2_override_meta_save‘ filter as can_save() returns false.

    I have the following filters running successfully:

    // To read from custom table.
    add_filter( 'cmb2_override_meta_value', 'dcwd_cmb2_override_meta_value', 10, 4 );
    // To get past can_save() checks. Returns true when my 2 fields are in $_POST.
    add_filter( 'cmb2_can_save', 'dcwd_cmb2_can_save', 10, 2 );

    but my ‘cmb2_override_meta_save‘ filter is not running. I also have ‘cmb2_override_tracking_number_meta_save‘ and ‘cmb2_override_tracking_url_meta_save‘ (to match field IDs) but they don’t run either.

    Partial code: https://pastebin.com/sEQr7Rcu

    • This reply was modified 1 year, 3 months ago by daymobrew. Reason: Make code comments easier to read
    Thread Starter daymobrew

    (@daymobrew)

    I can see that ‘cmb2_override_meta_value‘ is not being run because in CMB2_Field::__construct() $args[‘object_id’] is zero so $this->object_id is zero and $this->get_data() does not get called.

    If my field group has object_type=page then object_id will be the page ID.

    • This reply was modified 1 year, 3 months ago by daymobrew. Reason: Typo in filter name
    Plugin Author Justin Sternberg

    (@jtsternberg)

    To investigate, we’ll need your entire CMB2 code to try and reproduce it (and whatever testing steps to enable/test with HPOS).

    Thread Starter daymobrew

    (@daymobrew)

    Code: https://pastebin.com/PDFBNgaQ

    To set up HPOS in WooCommerce: https://woocommerce.com/document/high-performance-order-storage/#section-2

    Essentially: WooCommerce/Settings/Advanced/Features then click ‘High performance order storage (new)’. I also uncheck ‘Keep the posts and orders tables in sync (compatibility mode).’

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Ok, I spent a bit too much time on this, but I created an addon for this specifically: https://github.com/CMB2/cmb2-woocommerce-hpos-orders

    You’ll need the latest in the develop branch of CMB2: https://github.com/CMB2/CMB2

    Once the addon is installed, using woocommerce_page_wc-orders as an object_type in your metabox registration should “just work”. ??

    Thread Starter daymobrew

    (@daymobrew)

    Justin – thank you for all that work.

    I have replaced CMB2 with CMB2-develop and added cmb2-woocommerce-hpos-orders plugin.

    The meta box shows and the CSS is enqueued.

    The submitted values do not show when I Update the order. Nor is the data written to the wp_wc_orders_meta db table.

    I am happy to debug here – just let me know what areas I should look at.

    • This reply was modified 1 year, 3 months ago by daymobrew. Reason: Mention that values not in db
    Plugin Author Justin Sternberg

    (@jtsternberg)

    Have you pulled the most recent version of the develop branch? Also, how are you including the hpos lib? Provide your cmb2 code please.

    Thread Starter daymobrew

    (@daymobrew)

    I downloaded the zip from github. develop branch has version number 2.10.0.

    For hpos add-on I downloaded the zip from github and activated that as a plugin. I’ve been trying to debug in VSC but my breakpoints are ‘unverified’ and ignored so I just began adding error_log() calls to verify the code is being run. The CMB2_Woo_HPOS_Orders::_construct function. I then added error_log() to init_hooks but that did not run. I could find the do_action( 'cmb2_init_hooks' ) call anywhere in CMB2 2.10.1 or CMB2 develop. Similar issue for the add_filter() calls to cmb2_set_box_object_type and cmb2_set_box_object_type – cannot find the matching apply_filters() calls.

    • This reply was modified 1 year, 3 months ago by daymobrew. Reason: Add info about add_filter
    Thread Starter daymobrew

    (@daymobrew)

    My cmb2 code has not changes – still https://pastebin.com/PDFBNgaQ

    Thread Starter daymobrew

    (@daymobrew)

    So as not to override cmb2 2.10.1 I put the develop branch version in wp-content/plugins/CMB2-develop directory.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    That’s my fault, I forgot to actually push my local changes up. Please re-download the develop branch and try again!

    Thread Starter daymobrew

    (@daymobrew)

    That did it. I got a fresh copy from develop branch and the data is now loading and being stored in wp_wc_orders_meta table.

    View post on imgur.com

    Thank you.

    Should I mark this as resolved or wait until the branch is merged to main?

    Plugin Author Justin Sternberg

    (@jtsternberg)

    I marked it resolved. Will definitely need to get a release out soon.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘cmb2_override_meta_value filter not run on WooCommerce Edit Order page (HPOS)’ is closed to new replies.