As an attempt in being extra informative, using the latest WC and WP, I get two notices when displaying shipping data on the WooCommerce product page.
Notice: Undefined index: min_amount on line 89 and 91
I have the code in my theme's functions.php file and it worked fine until I started debugging everything (wp-config).
The errors refers to these two lines:
$cost = $instance['cost'] ? $instance['cost'] : $instance['min_amount'];
$above = $instance['min_amount'] ? 'above ' : '';
Can anyone please shed some insight as to where I am going wrong / what I am doing wrong here?
This is my code in full:
add_action( 'woocommerce_after_add_to_cart_form', 'shipping_on_product_page' );
function shipping_on_product_page() {
// get all zones
$zones = WC_Shipping_Zones::get_zones();
// get the shop base country
$base_country = WC()->countries->get_base_country();
$base_city = WC()->countries->get_base_city();
// start display of table
echo '<div>' . __( 'Available Shipping', 'woocommerce' );
echo '<br><small><span class="shipping-time-cutoff">All orders are shipped from the '.$base_country.'. Order before 12AM Mon-Fri for same day delivery within '.$base_city.'. Order before 3PM Mon-Thu for next day delivery.</span></small>';
echo '<small><table class="shipping-and-delivery-table">';
// get name of each zone and each shipping method for each zone
foreach ( $zones as $zone_id => $zone ) {
echo '<tr><td>';
echo '<strong>' . $zone['zone_name'] . '</strong>' . '</td><td>';
$zone_shipping_methods = $zone['shipping_methods'];
foreach ( $zone_shipping_methods as $index => $method ) {
$instance = $method->instance_settings;
$cost = $instance['cost'] ? $instance['cost'] : $instance['min_amount'];
$above = $instance['min_amount'] ? 'above ' : '';
echo $instance['title'] . ': ' . $above . '<strong>' . wc_price( $cost ) . '</strong>' . '<br>';
}
echo '</td></tr>';
}
echo '</table></small></div>';
}
