<?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.
use wp_gdpr_wc\controller;
in functions.php file. You can use$clasa = new wp_gdpr_wc\controller\Controller_Wc();
$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.add_action
twice in your code. you can removeadd_action( 'woocommerce_after_order_notes', array( $clasa, 'checkout_consent_checkbox' ) );
after the class is intantiatedadd_action( 'woocommerce_after_order_notes', array( $clasa, 'checkout_consent_checkbox' ) );
is not needed asadd_action( 'woocommerce_after_order_notes', array( $this, 'checkout_consent_checkbox' ) );
already triggers when the new instance of the class is created.use wp_gdpr_wc\controller; $clasa = new wp_gdpr_wc\controller\Controller_Wc();
, no other add_action, just a remove_action.