Need solution for "Fatal error: Uncaught Error: Class 'App\WC_Shipping_Rate' not found"

Hi,

Please excuse me if this is a rookie question but i’m still learning how this all works together.

I am currently building a theme for a client with woocommerce support and because of the specific nature of the client’s subject, I had to build a custom checkout process so I’m able to take all necessary data and present to user in a particular way.

This has all been figured out and it’s working however, I want to be able to change the shipping cost based on certain external factors. The order is manually added programmatically as soon as I have all the information however, as per this example, I need to be able to call “new WC_Shipping_Rate” from setup.php as there, I have the action that’s taking care of adding the order manually.

As mentioned above, I am however getting the Fatal error, Class not found in that particular line of code. So, my questions would be 1) is it possible to initiate a new object from the WC_Shipping_Rate class in setup.php and 2) If not, what would be the ideal way of going about this please?

Thanks!

Judging by the topic of this thread, it’s probably a namespace issue.

Since setup.php is defined with the namespace App (check the top of setup.php), you need to write new \WC_Shipping_Rate() to access the global class WC_Shipping_Rate().

For more info on namespaces as it relates to your issue: https://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.full
https://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.qualified
https://www.php.net/manual/en/language.namespaces.global.php

@folbert that was exactly it.

Many thanks for your kind and quick response… and also for the extra resources… very helpful and much appreciated!

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.