show flat shipping cost on product page woocommerce code example
Example 1: woocommerce display shipping cost on product page
add_action('woocommerce_single_product_summary', 'display_specific_shipping_class', 15 );
function display_specific_shipping_class(){
global $product;
$defined_shipping_class = "Estimated Delivery in 7-15 days";
$product_shipping_class = $product->get_shipping_class();
$term_name = get_term_by( 'slug', $product_shipping_class, 'product_shipping_class' );
if( $term_name == $defined_shipping_class ){
echo '<p class="product-shipping-class">' . $term_name . '</p>';
}
}
Example 2: Woocommerce custom Flat Rate charges (by ID) Function
function wc_ninja_change_flat_rates_cost( $rates, $package ) {
if ( isset( $rates['flat_rate:13'] ) ) {
$rates['flat_rate:13']->cost = 60;
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'wc_ninja_change_flat_rates_cost', 10, 2 );