Skip to content

Commit

Permalink
Merge pull request #262 from taxjar/258-fatal-error-in-product-page
Browse files Browse the repository at this point in the history
#258 Stop displaying the metabox when the order can't be found
  • Loading branch information
saville-stripe authored Aug 19, 2024
2 parents 6ebde2c + 384aad2 commit f460a3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
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

0 comments on commit f460a3e

Please sign in to comment.