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

Add support for WooCommerce Shipping Setting Enable debug mode #5

Open
bilfeldt opened this issue Mar 4, 2019 · 2 comments
Open

Add support for WooCommerce Shipping Setting Enable debug mode #5

bilfeldt opened this issue Mar 4, 2019 · 2 comments

Comments

@bilfeldt
Copy link
Member

bilfeldt commented Mar 4, 2019

If the setting WooCommerce->Settings->Shipping->Shipping options->Enable debug mode is enabled, then a bar with the matching shipping zone is shown during checkout and caching is disabled.

We should show how we calculated the shipping prices there as well. We are already showing how we calculate the shipping price in the error log, but it would be nice to show it there.
image

@bilfeldt
Copy link
Member Author

bilfeldt commented Mar 4, 2019

This is a Nice to have feature, so let us first find out if this can be done easily.

@bilfeldt
Copy link
Member Author

Basically this is how WooCommerce does it:

/**
 * Loads all shipping methods which are hooked in.
 * If a $package is passed some methods may add themselves conditionally and zones will be used.
 *
 * @param array $package Package information.
 * @return WC_Shipping_Method[]
 */
public function load_shipping_methods( $package = array() ) {
if ( ! empty( $package ) ) {
	$debug_mode             = 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' );
	$shipping_zone          = WC_Shipping_Zones::get_zone_matching_package( $package );
	$this->shipping_methods = $shipping_zone->get_shipping_methods( true );
	// Debug output.
	if ( $debug_mode && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! defined( 'WC_DOING_AJAX' ) && ! wc_has_notice( 'Customer matched zone "' . $shipping_zone->get_zone_name() . '"' ) ) {
		wc_add_notice( 'Customer matched zone "' . $shipping_zone->get_zone_name() . '"' );
	}
} else {
....

So when we add something to the log, then we can simply also add it using wc_add_notice() if the debug setting is enabled and then reuse the check they have:

$debug_mode = ('yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ));
if ( $debug_mode && ! defined( 'WOOCOMMERCE_CHECKOUT' ) && ! defined( 'WC_DOING_AJAX' ) ) {
    wc_add_notice($ss_log_entry);//This is where we add the log entry
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant