• Resolved 623carr

    (@623carr)


    Hello

    I am using this code from another of your forums but it’s not working on my site

    add_action( ‘wpo_wcpdf_after_order_data’, ‘wpo_wcpdf_cc_last_four’, 10, 2 );
    function wpo_wcpdf_cc_last_four ($template_type, $order) {
    if ($template_type == ‘invoice’) {
    $digits = $order->get_meta(‘_wc_square_credit_card_account_four’);
    $card_type = $order->get_meta(‘_wc_square_credit_card_card_type’);
    if (!empty($digits)) {
    ?>
    <tr class=”cc-four-digits”>
    <th>Last Four Digits:</th>
    <td><?php echo $digits; ?></td>
    </tr>
    <?php
    }
    if (!empty($card_type)) {
    ?>
    <tr class=”cc-type”>
    <th>Credit card:</th>
    <td><?php echo $card_type; ?></td>
    </tr>
    <?php
    }
    }
    }

    Please advise!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor Ewout

    (@pomegranate)

    Hi! It looks like you adapted that code from this thread, have you confirmed that you have used the correct meta keys for the data (_wc_square_credit_card_account_four and _wc_square_credit_card_card_type in your code). I recommend using the Store Toolkit to verify that this informtion is stored under those keys in the order data. If you found that data there, could you share a screenshot?

    Thread Starter 623carr

    (@623carr)

    Yes I did, here is the screenshot file:///Users/carolyns/Desktop/Screen%20Shot%202020-02-17%20at%202.36.42%20PM.png

    Thread Starter 623carr

    (@623carr)

    im putting this code in a child theme, im not sure if that makes a difference

    Plugin Contributor Ewout

    (@pomegranate)

    Screenshot doesn’t show, it links to a file on your computer ??
    Could you post this to https://imgbb.com/ or any other cloud service?
    Where in the child theme did you put this?

    Thread Starter 623carr

    (@623carr)

    Oh sorry!

    https://ibb.co/Zxkx66B

    I put it in the functions php

    Plugin Contributor Ewout

    (@pomegranate)

    Thanks for sharing that – these are indeed the correct meta keys. I saw your other post on this forum, and wondered if you are perhaps confusing plugins. Are you checking this in the PDF invoice generated by WooCommerce PDF Invoices & Packing Slips?

    Can you confirm whether the action code is executed at all by temporarily replacing

    
     $digits = $order->get_meta('_wc_square_credit_card_account_four');
    

    with

    
    $digits = 1234;
    
    Thread Starter 623carr

    (@623carr)

    Yea that was my bad, I need it on the invoices and the woocommerce receipts, so I do still need help with your plugin. I understand you can’t help with the woocommerce receipts.

    Plugin Contributor Ewout

    (@pomegranate)

    see edits above. If it doesn’t show, you may want to try different methods of adding the action, like the Code Snippets plugin to rule out any errors in the child theme setup.

    Thread Starter 623carr

    (@623carr)

    Ok i will try that and let you know, we already have the code snippets plugin installed. I’ve never used it personally.

    Thread Starter 623carr

    (@623carr)

    that did not seem to work

    https://ibb.co/b3sVJcf

    does this maybe not work with square as a processor?

    • This reply was modified 5 years, 1 month ago by 623carr.
    Plugin Contributor Ewout

    (@pomegranate)

    If the snippet using $digits = 1234; isn’t displaying anything, that means there’s something up with how it is added to your site rather than with Square itself – since that would bypass the meta data entirely and simply print 1234. So just to make sure we’re on the same page, can you confirm:

    • You’re using code snippets
    • The snippet is set to ‘active’
    • You’re using the default “Simple” template (not a customized version)
    • Your testing snippet looks like this:
    
    add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_cc_last_four', 10, 2 );
    function wpo_wcpdf_cc_last_four ($template_type, $order) {
    	if ($template_type == 'invoice') {
    		$digits = $order->get_meta('_wc_square_credit_card_account_four');
    		$digits = 1234;
    		$card_type = $order->get_meta('_wc_square_credit_card_card_type');
    		if (!empty($digits)) {
    			?>
    			<tr class="cc-four-digits">
    				<th>Last Four Digits:</th>
    				<td><?php echo $digits; ?></td>
    			</tr>
    			<?php
    		}
    		if (!empty($card_type)) {
    			?>
    			<tr class="cc-type">
    				<th>Credit card:</th>
    				<td><?php echo $card_type; ?></td>
    			</tr>
    			<?php
    		}
    	}
    }
    
    Thread Starter 623carr

    (@623carr)

    I added that exact code to a new “code snippet” and looked at an invoice/packing slip and still do not see the last 4 or CC type.

    I also still have it in my flatsome child theme as well.

    Plugin Contributor kluver

    (@kluver)

    Is the code snippet itself activated?

    Schermafbeelding-2020-02-19-om-15-36-53

    Thread Starter 623carr

    (@623carr)

    Yes it is :/

    Thread Starter 623carr

    (@623carr)

    Ok its working now, I deleted it from the child theme! thank you!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Add last 4 digits & card type of PDF invoices’ is closed to new replies.