0
<?php

namespace wp_gdpr_wc\controller;

use wp_gdpr\lib\Gdpr_Container;
use wp_gdpr_wc\lib\Gdpr_Wc_Translation;
use wp_gdpr_wc\model\Wc_Model;

class Controller_Wc {
    const REQUEST_TYPE = 3;

    /**
     * Controller_Form_Submit constructor.
     */
    public function __construct() {
        add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_consent_checkbox' ) );
    }   
public function checkout_consent_checkbox( $checkout ) {
        $privacy_policy_strings = Controller_Menu_Page_Wc::get_privacy_policy_strings();

        echo '<div class="gdpr_consent_class"><h3>' . __( 'GDPR permission: ', 'wp_gdpr' ) . '</h3>';

        woocommerce_form_field( 'gdpr_consent_checkbox', array(
            'type'     => 'checkbox',
            'label'    => $privacy_policy_strings[ Controller_Menu_Page_Wc::PRIVACY_POLICY_TEXT_WOO_REQUEST ],
            'required' => true,
        ), $checkout->get_value( 'gdpr_consent_checkbox' ) );

        echo '</div>';
    }

I'd like to change the woocommerce_after_order_notes hook from the add action with another hook. This is a class from a plugin. I tried to include that file in functions.php and initialize that class in a variable, but I get an error saying Fatal error: Uncaught Error: Class 'Controller_Wc' not found in functions.php

$path = get_home_path();
require_once $path . "/wp-content/plugins/wp-gdpr-wc-addon/controller/controller-wc.php";
$clasa = new Controller_Wc();
add_action( 'woocommerce_after_order_notes', array( $clasa, 'checkout_consent_checkbox' ) );

I tried to put controller-wc.php in child theme to overwrite the original one, but this did not work as well.

7
  • You nee to add use wp_gdpr_wc\controller; in functions.php file. You can use $clasa = new wp_gdpr_wc\controller\Controller_Wc(); Commented Jun 4, 2018 at 10:08
  • @BikashWaiba, just did, problem is that when I initialize it $clasa = new wp_gdpr_wc\controller\Controller_Wc(); the action runs one more time, any way to stop that? To be more clear, the action runs twice, one from the initialization and one from the original plugin, then I use remove_action and it removes one of them, the other one still there. I tried to remove it twice but does not work, tried a higher priority, same thing, one of them still there.
    – Alex
    Commented Jun 4, 2018 at 12:51
  • You have add_action twice in your code. you can remove add_action( 'woocommerce_after_order_notes', array( $clasa, 'checkout_consent_checkbox' ) ); after the class is intantiated Commented Jun 5, 2018 at 4:25
  • add_action( 'woocommerce_after_order_notes', array( $clasa, 'checkout_consent_checkbox' ) ); is not needed as add_action( 'woocommerce_after_order_notes', array( $this, 'checkout_consent_checkbox' ) ); already triggers when the new instance of the class is created. Commented Jun 5, 2018 at 4:31
  • I have just use wp_gdpr_wc\controller; $clasa = new wp_gdpr_wc\controller\Controller_Wc();, no other add_action, just a remove_action.
    – Alex
    Commented Jun 5, 2018 at 7:08

0

Your Answer

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

Browse other questions tagged or ask your own question.