• Resolved afwebdev

    (@afwebdev)


    When using the WC_Cart::add_fee() method, the following error is logged on the checkout page:

    Deprecated: Creation of dynamic property WC_Order_Item_Fee::$legacy_fee is deprecated in /{PATH}/wp-content/plugins/woocommerce/includes/class-wc-checkout.php on line 568

    This is on PHP 8.3, WC 9.3.3.

    Example code:

    function add_custom_fee( $cart )
    {
    if (is_admin() && !defined( 'DOING_AJAX' )) {
    return;
    }

    if ($cart instanceof WC_Cart) {
    $cart->add_fee( 'Processing Fee', 1.00, true );
    }
    }

    add_action( 'woocommerce_cart_calculate_fees', 'add_custom_fee' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hi @afwebdev,

    Thank you for reaching out.

    Looking at the shared error log, this seems to be a depreciated message due to the use of the $legacy_fee property in the WooCommerce WC_Order_Item_Fee class. This means that the use of $legacy_fee is no longer supported in the latest version of WooCommerce you are using (WC 9.3.3).

    In that case, I recommend making changes to your code in order to solve this issue. You can try the following steps:

    1. Running the exact code provided through an AI platform like ChatGPT for recommendations/changes to your code
    2. Checking whether there are existing plugins in the WordPress plugin repository that might be doing that already.
    3. Joining our WooCommerce Slack community (it does have a developer channel where you can ask coding questions): https://woo.com/community-slack/.

    I hope this helps.

    Thread Starter afwebdev

    (@afwebdev)

    That did not help – this is a bug in the code. I submitted a Github issue though – hopefully they’ll understand over there.

    Plugin Support Rajesh K. (woo-hc)

    (@rajeshml)

    Hello @afwebdev,

    Thank you for taking the time to submit an issue to the GitHub repository.

    Could you please share the GitHub issue you have posted so that we can confirm? It can also help other users with similar issues.

    Thanks!

    Thread Starter afwebdev

    (@afwebdev)

    Plugin Support Zubair Zahid (woo-hc)

    (@doublezed2)

    Hello afwebdev,

    Thank you for creating a GitHub report.
    I can see that our dev team has noticed it and has started processing it.

    Please don’t hesitate to contact us again if you have more questions or concerns.
    We are here to help ??

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.