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

#258 Stop displaying the metabox when the order can't be found #262

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions includes/admin/class-admin-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,31 @@ class Admin_Meta_Boxes {
* Admin_Meta_Boxes Constructor.
*/
public function __construct() {
add_action( 'add_meta_boxes', array( $this, 'add_order_meta_box' ), 30 );
add_action( 'add_meta_boxes', array( $this, 'add_order_meta_box' ), 30, 2 );
}

/**
* Add meta box to order post types.
*
* @param string $post_type Post type.
* @param \WP_Post $post Post object.
*/
public function add_order_meta_box() {
public function add_order_meta_box( $post_type, $post ) {
$wc_order = wc_get_order( $post->ID );

if ( ! $wc_order ) {
return;
}

foreach ( wc_get_order_types( 'order-meta-boxes' ) as $type ) {
add_meta_box(
'taxjar',
__( 'TaxJar', 'taxjar' ),
'\TaxJar\Order_Meta_Box::output',
$this->get_page_screen_id( $type ),
'normal',
'low'
'low',
array( 'order' => $wc_order )
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions includes/admin/class-order-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class Order_Meta_Box {
* Output meta box contents.
*
* @param mixed $post WP Post.
* @param array $additional_data Additional data.
*/
public static function output( $post ) {
$order_id = $post->ID;
$order = wc_get_order( $order_id );
public static function output( $post, $additional_data ) {
$order = $additional_data['args']['order'];

$metadata = self::get_order_tax_calculation_metadata( $order );
wp_enqueue_script( 'accordion' );

Expand Down