New here, and learning lots.
I’ve read up here about how you can “overwrite” functions from another Class using the extends code.

I’ve also realised that sometimes you need to use include_once to call for the file in particular which contains the class with the function I want to replace

My issue is that I’m either getting a full website crash (blank page) if I place my code without the include_once and with it, I get a Fatal Error showing up.

What I’m trying to do, is to override the Woocommerce Addon Product plugin so that it doesn’t add the price of an extra at the end of the meta title. (I’ve no idea why they have done this in the first palce ).

I’ve modified the plugin php file to test out if my fix works and it does. Now I just need to be able to override the function, which is what I’m trying here.

I’m wondering if it’s a syntax error or something. Hopefully you can help.

include_once '/wp-content/plugins/woocommerce-product-addons/includes/class-product-addon-cart.php'

class Addon_Remove_Price extends Product_Addon_Cart
{

public function order_line_item( $item, $cart_item_key, $values ) 
  {
  if ( ! empty( $values['addons'] ) ) 
    {
    foreach ( $values['addons'] as $addon ) 
      {
      $key = $addon['name'];

      $item->add_meta_data( $key, $addon['value'] );
        }
      }
  }
}

Read more here: PHP Class extends giving fatal error & crash in WordPress / Woocommerce function.php


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: