• Resolved kmalber

    (@kmalber)


    When a user tries to add a product along with a rechargeable product, the message: ‘You can not add another product while your cart contains with wallet rechargeable product’. I would like to customize the wording of this message. Is there a way I can do this? Perhaps in functions.php?

Viewing 6 replies - 1 through 6 (of 6 total)
  • arcticfclub

    (@arcticfclub)

    Just change your .po file in the woo-wallet/languages directory.
    Or… install a translation plugin, that taps into that.

    Plugin Author Subrata Mal

    (@subratamal)

    @kmalber You can modify the notice text using our plugin filter woo_wallet_restrict_other_from_add_to_cart.

    Thread Starter kmalber

    (@kmalber)

    Thank you both so much for your quick reply. I am relatively new to this and hope you might be able to provide a little more direction as to how to use the plugin filter. I have investigated the woo-wallet front end code to see where the filter function is defined and the hook at which it is added. I tried copying the function code into my function.php, modifying it to include my preferred message wording and hooking it to the same hook used in the front end code. The result is that the new error message is appended to the default message. Would you be able to instruct as to how I might instead remove the default message and replace it with my preferred text? Any help you could give would be most gratefully appreciated!

    add_filter(‘woocommerce_add_to_cart_validation’, ‘ka_neg_balance_msg’, 20);

    function ka_neg_balance_msg($valid ){
    $product = get_wallet_rechargeable_product();
    if ( is_wallet_rechargeable_cart() ) {
    wc_add_notice( apply_filters( ‘woo_wallet_restrict_other_from_add_to_cart’, __( ‘NEW MESSAGE WORDING’, ‘woo-wallet’ ) ), ‘error’ );
    $valid = false;
    }
    return $valid;
    }`

    Thread Starter kmalber

    (@kmalber)

    I think I may have figured it out. I amended the code to add a wc_clear_notices() prior to the wc_add_notice (code below). This appears to be working. Would you know if there is any reason which would counter-indicate using this method (eg could there be situations where there are stored notices besides this one error message that I wouldn’t want to clear)? Thanks so much for your help.

    add_filter(‘woocommerce_add_to_cart_validation’, ‘ka_neg_balance_msg’, 20);

    function ka_neg_balance_msg($valid ){
    $product = get_wallet_rechargeable_product();
    if ( is_wallet_rechargeable_cart() ) {
    wc_clear_notices();
    wc_add_notice( apply_filters( ‘woo_wallet_restrict_other_from_add_to_cart’, __( ‘NEW MESSAGE WORDING’, ‘woo-wallet’ ) ), ‘error’ );
    $valid = false;
    }
    return $valid;
    }`

    Plugin Author Subrata Mal

    (@subratamal)

    @kmalber Please find the attached code.

    add_filter('woo_wallet_restrict_other_from_add_to_cart', 'woo_wallet_restrict_other_from_add_to_cart_callback');
    
    function woo_wallet_restrict_other_from_add_to_cart_callback(){
       return 'NEW MESSAGE WORDING';
    }
    Thread Starter kmalber

    (@kmalber)

    Worked like a charm! Thank you so much for your help Subrata.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Way to customize Terawallet error message’ is closed to new replies.