Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]: Allow suppression of "Function is_internal_meta_key was called incorrectly" PHP notice #47538

Open
medavidallsop opened this issue May 16, 2024 · 2 comments
Labels
focus: order Issues related to orders. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton type: community contribution type: enhancement The issue is a request for an enhancement.

Comments

@medavidallsop
Copy link

Describe the solution you'd like

The following code will result in a PHP notice of "Notice: Function is_internal_meta_key was called incorrectly. Generic add/update/get meta methods should not be used for internal meta data, including "_billing_email". Use getters and setters."

$order = wc_get_order( 93 );
echo $order->get_meta( '_billing_email', true );

I understand the recommended method is to use $order->get_billing_email for the above, however in some scenarios the use of a generic $order->get_meta for internal keys is useful, just some examples of this could be that you're building functionality which allows a backend user to:

  • Type a set of meta keys to export the values (and some of these might be WooCommerce internal order meta keys)
  • Type a set of meta keys to read the value of and if they match make edits to the order programmatically (and some of these might be WooCommerce internal order meta keys)

In these scenarios the code will work, and due to the conditions of $order->get_meta() it does in fact use the internal meta function https://woocommerce.github.io/code-reference/files/woocommerce-includes-abstracts-abstract-wc-data.html#source-view.348

I'd like to see a means of being able to suppress that notice being done by is_internal_meta_key() https://woocommerce.github.io/code-reference/files/woocommerce-includes-abstracts-abstract-wc-data.html#source-view.329 for when you have a scenario like the 2 examples above, ideally with a PHP filter hook.

Describe alternatives you've considered

I understand there may be a means of checking if the meta being got is an internal Woo order meta key and instead calling the function, but I don't really see the point when it is already doing it via $order->get_meta, albeit with the notice, you'll just be duplicating what that is already doing.

Additional context

No response

@medavidallsop medavidallsop added the type: enhancement The issue is a request for an enhancement. label May 16, 2024
@tammullen tammullen added focus: order Issues related to orders. team: Proton labels May 17, 2024
@naman03malhotra
Copy link
Contributor

Hey @medavidallsop, thanks for creating this issue. You achieve it by doing the following:

// first, make sure that prop is allowed
if ( is_callable( $order, get_$prop_name ) ) { 
   $order->get_$prop_name();
} else {
   $order->get_meta( _prop_name ) 
}

@coreymckrill coreymckrill added the priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. label May 22, 2024
@medavidallsop
Copy link
Author

Aware of this, and can do it, however it is effectively just duplicating what already gets done by the get_meta() function, ideally I'd like to just let get_meta() take care of calling the function if is an internal meta key, but not log the PHP notice in this scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: order Issues related to orders. priority: normal The issue/PR is of normal priority—not many people are affected or there’s a workaround, etc. team: Proton type: community contribution type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

4 participants