• Resolved B

    (@blclda)


    Is there a way to edit the last two messages? Preferably in the plugin settings, without having to use another plugin or a code snippet.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi @blclda ,

    Greetings from WebToffee Support!

    Thanks for reaching out to us regarding the requirement you are seeking. Currently, the basic version of the plugin doesn’t provide the provision to customize the coupon messages within the plugin settings. It’s a premium version plugin functionality. If you’re interested, you can try out the plugin from here.

    Alternatively, you may use the below code if you wish. You can copy the code snippet provided below and paste it into your active theme’s functions.php file (WordPress Dashboard > Appearance > Theme Editor > functions.php), or you can use a Code Snippet plugin to do that for you.

    // Add filters to translate coupon messages
    add_filter( 'wt_smart_coupon_url_coupon_message', 'wbte_sc_translate_success_message', 10, 1 );
    add_filter( 'wt_smart_coupon_auto_coupon_message', 'wbte_sc_translate_success_message', 10, 1 );
    add_filter( 'wt_smart_coupon_click_to_apply_coupon_message_cart_empty', 'wbte_sc_translate_success_message', 10, 1 );
    
    // Translate coupon success messages based on the current locale.
    function wbte_sc_translate_success_message( $message ) {
        // Define translations
        $translations = array(
            'pt_PT' => array(
                'coupon_applied'                 => 'Cupom aplicado com sucesso!', // Coupon applied successfully!
                'coupon_applied_with_empty_cart' => 'Código do cupom aplicado com sucesso. Adicione produtos ao carrinho', // Coupon code applied successfully, Please add products into cart
            ),
        );
    
        // Check current locale
        $current_locale = get_locale();
    
        // Check if language is Portuguese (Portugal) and translate if needed
        if ( isset( $translations[ $current_locale ] ) ) {
            if ( 'wt_smart_coupon_click_to_apply_coupon_message_cart_empty' === current_filter() ) {
                $message = $translations[ $current_locale ]['coupon_applied_with_empty_cart'];
            } elseif ( 
                ( 'wt_smart_coupon_url_coupon_message' === current_filter() && WC()->cart->get_cart_contents_count() > 0 ) || 
                'wt_smart_coupon_auto_coupon_message' === current_filter() 
            ) {
                $message = $translations[ $current_locale ]['coupon_applied'];
            }
        }
    
        return $message;
    }
    
    // Add filter to translate free product added message
    add_filter( 'wt_sc_alter_free_product_added_message', 'wbte_sc_translate_free_product_message', 10, 3 );
    
    function wbte_sc_translate_free_product_message( $message, $product, $coupon_code ) {
        if ( 'pt_PT' === get_locale() 
            && class_exists( 'Wt_Smart_Coupon_Giveaway_Product' ) 
            && method_exists( 'Wt_Smart_Coupon_Giveaway_Product', 'get_product_giveaway_data' ) 
            && method_exists( 'Wt_Smart_Coupon_Giveaway_Product', 'is_full_free_item' )
            && $product
        ) {
            $giveaway_data = Wt_Smart_Coupon_Giveaway_Product::get_instance()->get_product_giveaway_data( $product->get_id(), $coupon_code );
            if ( Wt_Smart_Coupon_Giveaway_Product::get_instance()->is_full_free_item( $product, $giveaway_data ) ) {
                $message = __( 'Parabéns, você tem um brinde no carrinho!', 'wt-smart-coupons-for-woocommerce' ); // Congratulations, you've got a freebie in your cart!
            }
        }
    
        return $message;
    }

    In the code snippet, you may change the texts accordingly.

    Feel free to reach out if you need any further clarification or assistance. We’re here to help!

    Plugin Support WebToffee Support

    (@webtoffeesupport)

    Hi?@blclda ,

    We haven’t heard back from you for a while. As this thread has been inactive for some time, we are marking it as resolved.

    If you require any further assistance, please reach out to us using a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Translate these strings?’ is closed to new replies.