Alternative for the wc_add_to_cart_message hook in Woocommerce for WP

后端 未结 5 518
轮回少年
轮回少年 2020-12-17 00:48

I used the add to cart message hook in Woocommerce to edit the text and remove some classes from certain buttons. It seems this hook is now deprecated in Woocommerce 2.1 and

5条回答
  •  无人及你
    2020-12-17 01:03

    Woocommerce 2.3+,

        add_filter( 'wc_add_to_cart_message', 'custom_add_to_cart_message' );
        function custom_add_to_cart_message( $message  ){
        global $woocommerce;
    
        $added_text = __( 'Product was successfully added to your Network Kit.', 'woocommerce' );
        // Output success messages
        if ( get_option( 'woocommerce_cart_redirect_after_add' ) == 'yes' ) :
    
            $return_to  = apply_filters( 'woocommerce_continue_shopping_redirect', wp_get_referer() ? wp_get_referer() : home_url() );
    
            $message    = sprintf('%s %s', $return_to, __( 'Continue Shopping', 'woocommerce' ), $added_text );
    
        else :
    
            $message    = sprintf('%s %s', wc_get_page_permalink( 'cart' ), __( 'View your Network Kit', 'woocommerce' ), $added_text );
    
        endif;
    
        return $message;
    }
    

提交回复
热议问题