• Resolved famouswolluf

    (@famouswolluf)


    I use the flat_rate method for my shipping costs.
    It contains a default cost_per_order and I use 2 shipping_classes inside flat_rate for additional costs for some products.

    I want to show the shipping costs on the product page.
    Right now I use the $product->shipping_class_id() to get the ID but I can’t figure out how to get the costs for this shipping_class_id.
    Because if I konw the costs I can add this to the cost_per_order to calculate the total shipping costs for the product.

    I also can’t figure out how to get the cost_per_order value.

    If there is no solution at all, I can use as an emergency solution a switch/case statement and put the costs in there but then I need to change the code when I change the flat_rate costs, so I don’t prefer this kind of solutions.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter famouswolluf

    (@famouswolluf)

    I have figured it out:

    $shipping_class_id = $product->get_shipping_class_id();
    $shipping_class= $product->get_shipping_class();
    $fee = 0;
    
    if ($shipping_class_id) {
       $flat_rates = get_option("woocommerce_flat_rates");
       $fee = $flat_rates[$shipping_class]['cost'];
    }
    
    $flat_rate_settings = get_option("woocommerce_flat_rate_settings");
    echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);
    • This reply was modified 8 years, 4 months ago by famouswolluf.

    @famouswolluf Where you add this code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get shipping costs for a product’ is closed to new replies.