Skip to content

Commit

Permalink
Improve shipping method debug output.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Apr 18, 2024
1 parent 4ed903d commit db2eb20
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/ShippingMethod/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,29 +781,36 @@ public function calculate_shipping( $package = array() ) {
$debug_notices[] = sprintf( _x( '%1$s does not fit the available packaging options', 'shipments', 'woocommerce-germanized-shipments' ), $product_desc );
}
}
}

if ( $is_debug_mode && ! Package::is_constant_defined( 'WOOCOMMERCE_CHECKOUT' ) && ! Package::is_constant_defined( 'WC_DOING_AJAX' ) && ! empty( $debug_notices ) ) {
$the_notice = '';
$available_box_list = array();
if ( $is_debug_mode && ! Package::is_constant_defined( 'WOOCOMMERCE_CHECKOUT' ) && ! Package::is_constant_defined( 'WC_DOING_AJAX' ) && ! empty( $debug_notices ) ) {
$the_notice = '';
$available_box_list = array();

foreach ( $available_boxes as $box ) {
$available_box_list[] = $box->get_packaging()->get_title();
}
foreach ( $available_boxes as $box ) {
$available_box_list[] = $box->get_packaging()->get_title();
}

$general_debug_notices = array(
sprintf( _x( '### Debug information for %1$s:', 'shipments', 'woocommerce-germanized-shipments' ), $this->get_title() ),
sprintf( _x( 'Available packaging options: %1$s', 'shipments', 'woocommerce-germanized-shipments' ), implode( ', ', $available_box_list ) ),
);
$general_debug_notices = array(
sprintf( _x( '### Debug information for %1$s:', 'shipments', 'woocommerce-germanized-shipments' ), $this->get_title() ),
sprintf( _x( 'Available packaging options: %1$s', 'shipments', 'woocommerce-germanized-shipments' ), implode( ', ', $available_box_list ) ),
);

$debug_notices = array_merge( $general_debug_notices, $debug_notices );
if ( empty( $applied_rules ) ) {
foreach ( $packed_boxes as $packed_box_index => $box ) {
$packaging = $box->getBox();
$general_debug_notices[] = sprintf( _x( '## Packed box %1$d/%2$d: %3$s', 'shipments', 'woocommerce-germanized-shipments' ), ++$packed_box_index, count( $packed_boxes ), $packaging->getReference() );
}
}

foreach ( $debug_notices as $notice ) {
$the_notice .= $notice . '<br/>';
}
$debug_notices = array_merge( $general_debug_notices, $debug_notices );

if ( ! wc_has_notice( $the_notice ) ) {
wc_add_notice( $the_notice );
foreach ( $debug_notices as $notice ) {
$the_notice .= $notice . '<br/>';
}

if ( ! wc_has_notice( $the_notice ) ) {
wc_add_notice( $the_notice );
}
}
}
}
Expand Down

0 comments on commit db2eb20

Please sign in to comment.