Override the plugin class and function

Question

hope somebody could help me. I have bought one plugin. But I need to change the function of the plugin in my child template functions.php
Here is the classes and functions of the plugin. I need to change the function “get_product_price” with my value.

class TOP_Woo {
  public function __construct() {
    ..
    ..
    $this->init_hook();
  }

  public function init_hook() {
    add_filter( 'woocommerce_product_class', array( $this, 'my_product_class' ), 10, 4 );
  }

  public function my_product_class( $classname, $product_type, $post_type, $product_id) {
    $classname = 'SUB_WC_Product';
    return $classname;
  }

  public function load() {
    TOP_Woo::instance();
  }

  public static function instance() {
    if ( ! self::$_instance ) {
      self::$_instance = new self();
    }
    return self::$_instance;
  }
}
add_action( 'plugins_loaded', array( 'TOP_Woo', 'load' ) );


global $woocommerce;
class SUB_WC_Product extends WC_Product_Simple {
  public function __construct ( $product = 0 ) {
    $this->post = get_post( $this->id );
  }

  public function get_product_price( $context = 'view' ) {
    return "XY";
  }
}

Thank you! 🙂

0
, , Down 4 years 2020-03-04T19:50:59-05:00 0 Answers 105 views 0

Leave an answer

Browse
Browse