2

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! :)

1
  • There's nothing in that code that would allow you to change the value. Commented Mar 4, 2020 at 23:30

1 Answer 1

1

thanks... I dont know if is this good way, but this code in the child theme functions.php is working for me:

add_filter('woocommerce_product_class', 'myFunction', 10, 4);
function myFunction($classname, $product_type, $post_type, $product_id) {
    $classname = 'SUB_WC_Product_my';
    return $classname;
}

class SUB_WC_Product_my extends SUB_WC_Product {
    public function get_product_price( $context = 'view' ) {
        return "AB";
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.