• Resolved progressor

    (@progressor)


    I need to remove this hook:
    add_action( 'comment_form_before', [ $this, 'comments_link' ] );

    From here (class-wcml-comments.php), Code snippet:

    public function __construct( woocommerce_wpml $woocommerce_wpml, SitePress $sitepress, WPML_Post_Translation $post_translations, wpdb $wpdb ) {
        $this->woocommerce_wpml  = $woocommerce_wpml;
        $this->sitepress         = $sitepress;
        $this->post_translations = $post_translations;
        $this->wpdb              = $wpdb;
      }
    
      public function add_hooks() {
    
        add_action( 'comment_post', [ $this, 'add_comment_rating' ] );
        add_action( 'woocommerce_review_before_comment_meta', [ $this, 'add_comment_flag' ], 9 );
    
        add_filter( 'get_post_metadata', [ $this, 'filter_average_rating' ], 10, 4 );
        add_filter( 'comments_clauses', [ $this, 'comments_clauses' ], 10, 2 );
        add_action( 'comment_form_before', [ $this, 'comments_link' ] );
    
        add_filter( 'wpml_is_comment_query_filtered', [ $this, 'is_comment_query_filtered' ], 10, 2 );
        add_action( 'trashed_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
        add_action( 'deleted_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
        add_action( 'untrashed_comment', [ $this, 'recalculate_average_rating_on_comment_hook' ], 10, 2 );
        //before WCML_Synchronize_Product_Data::sync_product_translations_visibility hook
        add_action( 'woocommerce_product_set_visibility', [ $this, 'recalculate_comment_rating' ], 9 );
    
        add_filter( 'woocommerce_top_rated_products_widget_args', [ $this, 'top_rated_products_widget_args' ] );
        add_filter( 'woocommerce_rating_filter_count', [ $this, 'woocommerce_rating_filter_count' ], 10, 3 );
      }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Pierre Sylvestre

    (@strategio)

    @progressor,

    Here’s a suggestion:

    
    global $woocommerce_wpml;
    
    if ( isset( $woocommerce_wpml->comments ) ) {
        add_action( 'comment_form_before', [ $woocommerce_wpml->comments, 'comments_link' ] );
    }
    

    However, be careful with this change, the action you want to remove could change in the future.

    Thread Starter progressor

    (@progressor)

    @strategio,

    I checked your action but it doesn’t work. The desired hook is not removed.
    Can you suggest anything else? Thanks!

    Plugin Author Pierre Sylvestre

    (@strategio)

    @progressor,

    I didn’t mention any hook because I didn’t know where you wanted to this.

    This should be done after init (with priority > 2, so the default 10 should be enough):

    
    add_action( 'init', function() {
        global $woocommerce_wpml;
        
        if ( isset( $woocommerce_wpml->comments ) ) {
            add_action( 'comment_form_before', [ $woocommerce_wpml->comments, 'comments_link' ] );
        }
    } );
    

    Let me know if this helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to remove the hook correctly?’ is closed to new replies.