Search code examples
phpwordpresswoocommercehook-woocommercepoints

Remove product variation message in Woocommerce points & rewards plugin


I'm trying to create a remove action for the woocommerce points and rewards plugin but I cannot get it to work.

I haven't tried to remove an action that's like this before so any help would be appreciated :)

Thank you for reading

My remove_action is :

remove_action( 'woocommerce_before_add_to_cart_button', 'add_variation_message_to_product_summary', 25 );

The original add_actions in their class:

    class WC_Points_Rewards_Product {
        /**
         * Add product-related hooks / filters
         *
         * @since 1.0
         */
        public function __construct() {

            // add single product message immediately after product excerpt
            add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'render_product_message' ), 15 );

            // add variation message before the price is displayed
            add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_variation_message_to_product_summary' ), 25 );

            // add the points message just before the variation price.
            add_filter( 'woocommerce_variation_price_html', array( $this, 'render_variation_m

essage' ), 10, 2 );
        add_filter( 'woocommerce_variation_sale_price_html', array( $this, 'render_variation_message' ), 10, 2 );
        add_filter( 'woocommerce_available_variation', array( $this, 'render_available_variation_message' ), 10, 3 );

        add_filter( 'woocommerce_show_variation_price', '__return_true' );

        // delete transients
        add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_transients' ) );
    }

and the function which im trying to remove:

/**
     * Add a message about the points to the product summary
     *
     * @since 1.2.6
     */
    public function add_variation_message_to_product_summary() {
        global $product;

        // make sure the product has variations (otherwise it's probably a simple product)
        if ( method_exists( $product, 'get_available_variations' ) ) {
            // get variations
            $variations = $product->get_available_variations();

            // find the variation with the most points
            $points = $this->get_highest_points_variation( $variations, $product->get_id() );

            $message = '';
            // if we have a points value let's create a message; other wise don't print anything
            if ( $points ) {
                $message = $this->create_variation_message_to_product_summary( $points );
            }

            echo $message;
        }
    }

EDIT I forgot to mention that if you comment out this then the info im trying to remove is actually removed.

//add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'add_variation_message_to_product_summary' ), 25 );

Additional info

I didn't mention this before because i thought it would only bloat the question but the goal is to remove it from where it is (before add to cart) and add it back in under the price, so effectively moving it up the page.

I didn't include this before as i thought it would be a simple remove add action.


Solution

  • add_filter( 'wc_points_rewards_single_product_message', 
    'remove_rewards_earn_points_message_single', 15, 2 );
    function remove_rewards_earn_points_message_single( $message, $data ) {
    if( is_product() )
        return '';
    return $message;
    }
    

    Can be removed by this, but i don`t know how to add it back to another location (