Support » Plugin: WooCommerce Smart COD » Ultralight weight request

  • Resolved Adrenaline22

    (@slogmaps)


    Dear developer,

    First of all thank you for this plugin. I have bought several other payment method fee plugins but none of them equal the functionality of this one.

    I would like to propose a minor modification, I am also willing to pay for, since I am in a hurry.

    I would like to put the fee in small text right title of the COD payment method:

    ° Paypal
    ° Credit Card
    ° Cash on Delivery (2,00€ fee)

    The string “Fee” should be translatable of course.

    All the best

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi Adrenaline22,

    Thanks for your kind words.
    Yes we can find a way to provide this functionality, maybe through a filter I have to check this just to be sure.

    As for your willingness to pay, that’s something that is prohibited by the wordpress org rules, but if you want to help us there is always the donate button 🙂

    Best Regards

    Thread Starter Adrenaline22

    (@slogmaps)

    Evharisto!

    I donated 🙂

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi Adrenaline22,

    Thanks a lot for your donation.
    We will provide a solution to your request shortly.

    Best Regards

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi Adrenaline22,

    Your feature is now ready :).

    Please proceed to the following steps.

    a.) Replace your wp-content/plugins/wc-smart-cod/public/class-wc-smart-cod-public.php with the one I send you in the following WeTransfer ( I’m going to integrate this code in the next release of the plugin, so you don’t have to replace it more than once ).
    WeTransfer Link: https://wetransfer.com/downloads/7422a684f862382e638025e046d9162d20180215205034/0d958d91a6f440753ce19ae54659c8d420180215205034/ec0828

    b.) Copy paste this code block in your theme’s functions.php

    add_action( 'woocommerce_update_order_review_fragments', 'insert_price_to_title' );
    
    function insert_price_to_title( $data ) {
    
    	// settings
    	$string = __( 'fee', 'wc-smart-cod' );
    	// settings end.
    
    	global $woocommerce;
    
    	$doc = new DOMDocument();
    	$doc->loadHTML( mb_convert_encoding( $data[ '.woocommerce-checkout-payment' ], 'HTML-ENTITIES', 'UTF-8' ) );
    	$finder = new DomXPath( $doc );
    	$classname = 'payment_method_cod';
    	$node = $finder->query( "//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]" );
    	$label = $node->item( 0 );
    
    	if( ! $label ) return $data;
    
    	$label = $label->getElementsByTagName( 'label' )->item( 0 );
    
    	$smart_cod = new Wc_Smart_Cod_Public( 'wc-smart-cod' );
    	$fee = $smart_cod->apply_smart_cod_fees( $woocommerce->cart, false );
    	$fee = wc_price( $fee, true );
    	$fee = sprintf( '<span>%s %s</span>', html_entity_decode( $fee, null, "UTF-8" ), $string );
    	$fragment = $doc->createDocumentFragment();
    	$fragment->appendXML( '<span>(' . $fee . ')</span>' );
    
    	$label->appendChild( $fragment );
    
    	$doc->removeChild( $doc->doctype );
    	$doc->replaceChild( $doc->firstChild->firstChild->firstChild, $doc->firstChild );
    
    	$data[ '.woocommerce-checkout-payment' ] = $doc->saveHTML();
    
    	return $data;
    }

    c.) The string “fee” is translatable under our text domain ( wc-smart-cod ). You can change this to your theme’s text domain, if you want.

    And you are ready. Please let me know if any issues.

    Best Regards

    Thread Starter Adrenaline22

    (@slogmaps)

    Hi,

    – It’s working now. We are almost there 🙂

    – I have my site in 5 languages. The word ‘fee’ should be easily translatable. Surcharges are an problematic thing for customers, so it’s sound to have the word ‘fee’ in translated in the their language.

    -I also made the text smaller as in other plugins. It would be easies if you would make the text smaller by default or at least give it a class so it can be easily accessible.

    #payment > ul > li.wc_payment_method.payment_method_cod > label > span{
        font-size:80%;
    }
    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi,

    For the class on the span please replace

    $fee = sprintf( '<span>%s %s</span>', html_entity_decode( $fee, null, "UTF-8" ), $string );

    with

    $fee = sprintf( '<span class="%s">%s %s</span>', 'wsc-input-fee', html_entity_decode( $fee, null, "UTF-8" ), $string );

    Change ‘wsc-input-fee’ with the classname of your choice, if you prefer.

    Now for the translate part. As you can see the string is translate ready:
    $string = __( ‘fee’, ‘wc-smart-cod’ );
    Are you familiar with gettext and po – mo files?
    Do you use WPML for the translations?

    Best Regards

    Thread Starter Adrenaline22

    (@slogmaps)

    Thanks!

    I use Loco translate. I synced the translation template file, but there is no string for “fee”.

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi,
    I will check this and give you a solution soon.

    Best Regards

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi again,

    I’ve figured out two solutions for you.

    At first, the reason loco translate can’t find the “fee” string inside our plugin, is because the string is in your functions.php and not in the plugin.

    First solution:

    Change

    $string = __( 'fee', 'wc-smart-cod' );

    with

    $string = __( 'Fee', 'woocommerce' );

    The “F” should be uppercase.
    And let the WooCommerce’s translation take over. ( You should have installed the WooCommerce translations of all the languages you use in your site. )

    Second solution:

    Use $string = __( 'fee', 'xxxxxx' );

    Where xxxxxx should be your theme’s text domain. E.g if you use storefront, it should be $string = __( 'fee', 'storefront' );

    1. Then go to Loco Translate / Themes
    2. Click in your theme’s name / Setup ( Here you can find the text domain as well
    3. In source file paths, add “functions.php” without the quotes and click Save Config
    4. Go to Overview / Edit Template and click Sync
    5. The fee string should now be scanned. Click Save

    Now go to your languages and translate it one by one.
    Let me know if any issues.

    Best Regards

    • This reply was modified 3 years, 6 months ago by FullStack-ing.
    Thread Starter Adrenaline22

    (@slogmaps)

    The first method did it. Had no success with the second. All is good.

    You are great, thanks!

    Plugin Author FullStack-ing

    (@fullstackhouse)

    Hi,

    No problem at all and thanks for your support. 🙂
    It will be lot appreciated, if you give us a review.

    Best Regards

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Ultralight weight request’ is closed to new replies.