need help removing action from plugin file

前端 未结 6 1595
醉话见心
醉话见心 2021-01-22 03:10

Hello I am trying to remove an action from a wordpress plugin file. The plugin is called Woocommerce Points and Rewards. I have found the action I want to remove in one of the

6条回答
  •  生来不讨喜
    2021-01-22 03:54

    I was able to figure out how to remove the render_redeem_points_message effectively with the following code:

    /* Removes render_redeem_points_message() */
    function wc_remove_points_message() {
        global $woocommerce;
        global $wc_points_rewards;
    
        // Removes message from cart page
        remove_action( 'woocommerce_before_cart', array( $wc_points_rewards->cart, 'render_redeem_points_message' ), 16 );
    
        // Removes message from checkout page
        remove_action( 'woocommerce_before_checkout_form', array( $wc_points_rewards->cart, 'render_redeem_points_message' ), 6 );
    
    }
    // Removes action on init
    add_action( 'init', 'wc_remove_points_message' );
    

    To share a bit more, I wanted to create a minimum purchase amount to be able to redeem points:

    /* Adds Minimum Order for Points Redemption */
    function wc_min_order_points_message() {
        global $woocommerce;
        global $wc_points_rewards;
    
        // Get cart subtotal, excluding tax
        $my_cart_total = $woocommerce->cart->subtotal_ex_tax;
    
        if ($my_cart_total < 30) { // $30 minimum order
    
            remove_action( 'woocommerce_before_cart', array( $wc_points_rewards->cart, 'render_redeem_points_message' ), 16 );
            remove_action( 'woocommerce_before_checkout_form', array( $wc_points_rewards->cart, 'render_redeem_points_message' ), 6 );
    
        } // endif $my_cart_total
    
    
    }
    // Adds action for cart and checkout pages instead of on init
    add_action( 'woocommerce_before_cart', 'wc_min_order_points_message' );
    add_action( 'woocommerce_before_checkout_form', 'wc_min_order_points_message' );
    

    I hope this helps anyone else trying to similarly expand on the WooCommerce Points and Rewards plugin.

提交回复
热议问题