How to override a plugins script

I use the plugin woocommerce simple auctions, and to make it fit my needs, i have done some customizations to a file inside the plugin. I need to somehow be able to override the original function, or parts of it, with my own modification. How do i do so?

Original function look like this:

            public function __construct(){
            $this->plugin_prefix    = 'wc_simple_auctions';
            $this->plugin_basefile  = plugin_basename(__FILE__);
            $this->plugin_url       = plugin_dir_url($this->plugin_basefile);
            $this->plugin_path      = trailingslashit(dirname(__FILE__));

            $this->auction_types = array('normal' => __('Normal', 'wc_simple_auctions'), 'reverse' => __('Reverse', 'wc_simple_auctions'));
            $this->auction_item_condition = array('new' => __('New', 'wc_simple_auctions'), 'used' => __('Used', 'wc_simple_auctions'));

            add_action('woocommerce_init', array(&$this, 'init'));
            //require_once( ABSPATH .'wp-includes/pluggable.php');              
        }

I need it to be overriden by this change:

            public function __construct(){
            $this->plugin_prefix    = 'wc_simple_auctions';
            $this->plugin_basefile  = plugin_basename(__FILE__);
            $this->plugin_url       = plugin_dir_url($this->plugin_basefile);
            $this->plugin_path      = trailingslashit(dirname(__FILE__));

            $this->auction_types = array('normal' => __('Normal', 'wc_simple_auctions'), 'reverse' => __('Reverse', 'wc_simple_auctions'));
            $this->auction_item_condition = array('new' => __('Brand New', 'wc_simple_auctions'), 'used' => __('1/10', 'wc_simple_auctions'),
            '2/10'=> __('2/10', 'wc_simple_auctions'), '3/10'=> __('3/10', 'wc_simple_auctions'), '4/10'=> __('4/10', 'wc_simple_auctions'), '5/10'=> __('2/10', 'wc_simple_auctions'), '6/10'=> __('6/10', 'wc_simple_auctions'), '7/10'=> __('7/10', 'wc_simple_auctions'), '8/10'=> __('8/10', 'wc_simple_auctions'), '9/10'=> __('9/10', 'wc_simple_auctions'), '10/10'=> __('10/10', 'wc_simple_auctions'));

            add_action('woocommerce_init', array(&$this, 'init'));
            //require_once( ABSPATH .'wp-includes/pluggable.php');              
        }

How do I do so?

The snippet, where the above is called has been added here:

            public function product_write_panel(){
            global $post;
            $product     = get_product( $post->ID );

            // Pull the video tab data out of the database
            $tab_data = maybe_unserialize(get_post_meta($post->ID, 'woo_auction_tab', true));
            if(empty($tab_data)){
                $tab_data[] = array();
            }
            echo '<div id="auction_tab" class="panel woocommerce_options_panel">';

            woocommerce_wp_select( array( 'id' => '_auction_item_condition', 'label' => __( 'Item condition', 'wc_simple_auctions' ), 'options' => apply_filters( 'simple_auction_item_condition',$this->auction_item_condition) ) );

}

1

Answers


  1. Mark Kaplun
    -1 Votes

    In principal, unless there are documented APIs and/or filters to the plugin, you should not do anything that is more then using core hooks if you want to be able to upgrade it in the future.

    If no appropriate thing is available, you should contact the author and ask for it, or decide that you are taking full responsibility and just fork it.

    In your specific case, you might be able to change the attribute after the initialization of the object, but next version this attribute might not be there any more.

    Edit:
    since there is a filter you just need to use it like

    function wpse_242093_auctions($auctions) {
      return array('new' => __('Brand New', 'wc_simple_auctions'), 'used' => __('1/10', 'wc_simple_auctions'),
                '2/10'=> __('2/10', 'wc_simple_auctions'), '3/10'=> __('3/10', 'wc_simple_auctions'), '4/10'=> __('4/10', 'wc_simple_auctions'), '5/10'=> __('2/10', 'wc_simple_auctions'), '6/10'=> __('6/10', 'wc_simple_auctions'), '7/10'=> __('7/10', 'wc_simple_auctions'), '8/10'=> __('8/10', 'wc_simple_auctions'), '9/10'=> __('9/10', 'wc_simple_auctions'), '10/10'=> __('10/10', 'wc_simple_auctions'));
    }
    
    add_filter('simple_auction_item_condition','wpse_242093_auctions');
    
Please signup or login to answer this question.

Signup for an account and start participating in our site today!




Social Signup

You can also login with your Facebook, Twitter or Linkedin account

Log in with Facebook