So I have this plugin code
class WC_List_Grid { public function __construct() { add_action( 'wp' , array( $this, 'setup_gridlist' ) , 20); } function setup_gridlist() { add_action( 'woocommerce_before_shop_loop', array( $this, 'gridlist_toggle_button' ), 30); } function gridlist_toggle_button() {?> <nav class="gridlist-toggle"> <a href="#" id="grid" title="<?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-grid-view"></span> <em><?php _e( 'Grid view', 'woocommerce-grid-list-toggle' ); ?></em></a> <a href="#" id="list" title="<?php _e('List view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-exerpt-view"></span> <em><?php _e( 'List view', 'woocommerce-grid-list-toggle' ); ?></em></a> </nav> <?php } }
I want to change the contents of the gridlist_toggle_button function. This is how I plan to change the contents of this function. Like writing another function with almost the same html as the original, but a bit of my changes. Sort of
add_action('woocommerce_before_shop_loop','new_gridlist_toggle_button') function new_gridlist_toggle_button() {?> <nav class="gridlist-toggle"> <a href="#" class="grid-view" title="<?php _e('Grid view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-grid-view"></span> <em><?php _e( 'Grid view', 'woocommerce-grid-list-toggle' ); ?></em></a> <a href="#" class="list-view" title="<?php _e('List view', 'woocommerce-grid-list-toggle'); ?>"><span class="dashicons dashicons-exerpt-view"></span> <em><?php _e( 'List view', 'woocommerce-grid-list-toggle' ); ?></em></a> </nav> <?php } }
This way, I donโt have to directly change the plugin files
For this, I am trying to remove a related action.
add_action( 'woocommerce_before_shop_loop', array( $this, 'gridlist_toggle_button' ), 30);
So that I can use my own code. But I can not delete this action. I have tried this so far.
Method 1:
global $WC_List_Grid ; remove_action( 'woocommerce_before_shop_loop', array( $WC_List_Grid, 'gridlist_toggle_button' ), 100);
Method 2:
function remove_plugin_actions(){ global $WC_List_Grid ; remove_action( 'woocommerce_before_shop_loop', array( $WC_List_Grid, 'gridlist_toggle_button' ), 100); } add_action('init','remove_plugin_actions');
Method 3
remove_action( 'woocommerce_before_shop_loop', array( 'WC_List_Grid', 'gridlist_toggle_button' ), 100);
None of them seem to work.
With a little brainstorming, I think there may be two possible reasons.
- It does not work, because the action I want to delete is not directly attached to the hook. Its action is within action.
- I am trying to block the output of gridlist_toggle_button via functions.php. But if the plugins are loaded before functions.php, then the function that should be blocked is already called and, therefore, it always shows the output.
I am not very good at OOP. Can someone please help me?