Is it possible to override a variable in a plugin function without altering the plugin?

The closest thread I found to answer this problem is this one : Pass A Value From Outside To A Plugin Variable

However, it requires modifying the plugin code and I want to avoid this as far as possible.

The plugin function goes like this :

        add_action( 'woocommerce_before_single_product_summary', array( &$this, 'add_product_designer'), 15 );
        public function add_product_designer() {
        global $post, $wpdb, $product, $woocommerce;
        $master_id = fpd_get_master_id( $post->ID );
        $fancy_product = new Fancy_Product( $master_id );
        $open_in_lightbox = $fancy_product->get_option('open_in_lightbox') && trim($fancy_product->get_option('start_customizing_button')) != '';
        echo "<span class='openlightbox'>Result : $open_in_lightbox</span>";
        if( is_fancy_product( $master_id  ) && (!fpd_start_customizing_button_used($post->ID) || $open_in_lightbox) ) {
            // A bunch of code }

I’d like to change the variable $open_in_lightbox programmatically, so far I have something like this :

add_filter( 'woocommerce_before_single_product_summary', 'add_product_designer', 99 );
function add_product_designer($open_in_lightbox) {
    if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
        if ( is_product() && ( has_term( 'customization', 'product_cat' ) ) ) {
                global $open_in_lightbox;
                $open_in_lightbox = '1';
                echo "<a href='#'>YOU ARE IN THE LOOP!</a>";
                return $open_in_lightbox;

I also have to control the output of the function fpd_start_customizing_button_used($post->ID), which goes like that :

function fpd_start_customizing_button_used( $product_id ) {
$fancy_product = new Fancy_Product($product_id);
return trim($fancy_product->get_option('start_customizing_button')) != '' && !isset($_GET['start_customizing']) && !isset($_GET['cart_item_key']);

At this point I’m a bit lost because a) $open_in_lightbox returns nothing, b) I haven’t found out how to override get_option. Any guidance or resource that could be helpful would be greatly appreciated!

Thank you.

Read more here: Override A Plugin Variable And Function Via Functions.php


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: