Hi Mike,
I understand that shipping normally isn’t calculated until checkout. However, for my current project I need to show flat rate shipping on the product page.
I’m not sure what you mean by, “add the the short/long description.”
In lieu of using built-in functionality, I wrote this function to obtain an individual product’s shipping cost for the Flat Rate shipping method (does not work with fees, defaults to 1 quantity):
function wc_get_flat_rate_shipping_cost( $product_object ) {
$flat_rate_settings = maybe_unserialize( get_option( 'woocommerce_flat_rate_settings' ) );
$base_rate = isset( $flat_rate_settings['cost'] ) ? $flat_rate_settings['cost'] : 0;
$key = 'class_cost_' . $product_object->get_shipping_class();
$class_rate = isset( $flat_rate_settings[$key] ) ? $flat_rate_settings[$key] : 0;
$class_rate = str_replace( '[qty]', 1, $class_rate );
$class_rate = str_replace( '[cost]', $product_object->price, $class_rate );
$class_rate = (int)$class_rate;
$total = ( isset( $base_rate ) && isset( $class_rate ) ) ? $base_rate + $class_rate : 0;
return $total;
}
Unless there is a function that I should be using from the WC_Shipping or WC_Shipping_Flat_Rate classes, I will mark this as resolved.