WooCommerce Thankyou tracking code installation placement - php

I am new to Wordpress development and am trying to install a traffic junky tracking code on the thankyou.php page.
My attempt has failed so far and I think it boils down to not understanding PHP well enough.
The two tracking codes from trafficjunky that were available were HTML or PHP
HTML:
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
PHP:
<?php
$randomNumber = time() . mt_rand(1000, 9999999);
$currentPage = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
I tried to install the HTML version after the order processes under some PHP code on the thankyou.php WooCommerce template:
**<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<li class="woocommerce-order-overview__order order">
<?php _e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="woocommerce-order-overview__date date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
</li>
<?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
<li class="woocommerce-order-overview__email email">
<?php _e( 'Email:', 'woocommerce' ); ?>
<strong><?php echo $order->get_billing_email(); ?></strong>
</li>
<?php endif; ?>
<li class="woocommerce-order-overview__total total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php _e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
</li>
<?php endif; ?>
</ul>
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
<?php endif; ?>
</div>**
This led to order errors so i am trying to figure out how to add the PHP version of the tracking code safely without throwing errors.
Any help would be appreciated.
Thank you for the replies, I have set up the function in functions.php as instructed but I am still having trouble getting the tracking code to fire. Here is my current code:
add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );
function tracking_code_thankyou($order_id){
$random_number = time() . mt_rand(1000, 9999999);
$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<em>Your tracking code just below (for testing)</em>
<img id="1000145711_cpa_testing" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
<?php
}
}

You can try adding the php tracking code inside the header.php (before the end of the head tag) or footer.php (before the end of the body tag). You need to get the id of the page if you want it to run exclusively on that page only.
Do something like this
if(is_page(yourpageidhere)):
//paste the tracking code here
endif;

UPDATED
Instead of overriding the thankyou.php template as you can see its source code there is this line:
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
Which means that you can use this woocommerce_thankyou action hook with a custom function, to output anything in this template line. First get the template clean of your code...
Also I have corrected your code in the image link, as it was not correct. You should use the following code in the function.php file of your active child theme or active theme:
add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );
function tracking_code_thankyou( $order_id ) {
$random_number = time() . mt_rand(1000, 9999999);
$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
$url = "https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=$randomNumber&epu=$currentPage&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]";
echo '<em>Your tracking code just below (for testing)</em>
<img id="1000143661_tester" src="'.$url.'" width="1" height="1" border="0" />';
}
It will output your code just after customers details at the end of the order-received page…

Related

How to truncate a card

Here is a piece of my code.
<div class="thim-course-grid">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="lpr_course <?php echo 'course-grid-' . $columns; ?>">
**<div class="course-item" onmouseover="hide_card('<?= get_the_ID()?>');" onmouseout="show_card('<?= get_the_ID()?>');">**
<div class="course-thumbnail" id="course-thumbnail-<?= get_the_ID()?>">
<a href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>">
<?php echo thim_get_feature_image( get_post_thumbnail_id( get_the_ID() ), 'full', $thumb_w, $thumb_h, get_the_title() ); ?>
</a>
<?php do_action( 'thim_inner_thumbnail_course' ); ?>
<!-- <a class="course-readmore"
href="<?php echo esc_url( get_the_permalink( get_the_ID() ) ); ?>"><?php echo esc_html__( 'Read More', 'eduma' ); ?></a> -->
</div>
<div class="thim-course-content" id="thim-course-content-<?= get_the_ID()?>">
<?php learn_press_courses_loop_item_instructor();
the_title( sprintf( '<h2 class="course-title">', esc_url( get_permalink() ) ), '</h2>' );
?>
<?php if ( class_exists( 'LP_Addon_Coming_Soon_Courses_Preload' ) && learn_press_is_coming_soon( get_the_ID() ) ): ?>
<div class="message message-warning learn-press-message coming-soon-message">
<?php esc_html_e( 'Coming soon', 'eduma' ) ?>
</div>
<?php else: ?>
<div class="course-meta">
<?php learn_press_courses_loop_item_instructor(); ?>
<?php thim_course_ratings(); ?>
<?php learn_press_courses_loop_item_students(); ?>
<?php thim_course_ratings_count(); ?>
<?php learn_press_courses_loop_item_price(); ?>
</div>
<?php learn_press_courses_loop_item_price(); ?>
<?php endif; ?>
<div class="course-readmore">
<?php esc_html_e( 'Read More', 'eduma' ); ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
?>
</div>
On the 4th line, I wanted to truncate the course maps on mouse over, so that all the part of the map at the bottom of the image disappears, only to reappear when there is no more flyover. The result obtained is different from what I wanted.
I put the link to the site to see: www.formatine.com
And here is the JS part that I added as well.
function hide_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'none';
document.getElementById('course-thumbnail-'+id).innerHTML = "<?= wp_oembed_get( $media_intro ) ?>";
}
function show_card(id) {
document.getElementById('thim-course-content-'+id).style.display = 'block';
document.getElementById('course-thumbnail-'+id).style.display = 'block';
}
Do you have an idea for me please? Thank you.
Don't use "display: none" because once it has it, the element "disappears".
It is better for you, to then, if you want to include a video instead of the card, for example, do it by having both, one behind the other by default, if you "mouseover" display the code INSIDE of one, and on "mouseout", display the other.
<div class="mycard">
<div class="myinfoforthevideo"></div>
<div class="myvideo"></div>
</div>
You controll the events on mycard class, and hide myinfoforthevideo by default, on "mouseover", hide it and show then myvideo, and on "mouseout" hide myvideo and show myinfoforthevideo
You're hidding everything so now since its a width: 0/height: 0 let's say, you don't have any place to do the mouseover now.
Extra:
You can try flip cards as another option, like this:
https://codepen.io/Aoyue/pen/pLJqgE

How do I remove billing address from the thank you page?

So I want to remove the billing address from the thank you page. I am using wordpress and have the theme Impreza.
I have targeted the .woocommerce-customer-details and set to display: none; which worked on the google inspector mode but saved and refreshed and it still shows up. And I have checked the woo-commerce template files and found the order-details-customer.php is generating the information. I added a class to remove that section but it still shows up.
Woocommerce thank you page
In theme find a folder named woocommerce if not exist then Create folder:
Copy this file
/wp-content/plugins/woocommerce/templates/checkout/thankyou.php
and paste it into your active theme directory something like this
/wp-content/themes/activetheme/woocommerce/checkout/thankyou.php
And remove this
<ul class="woocommerce-thankyou-order-details order_details">
<li class="order">
<?php _e( 'Order Number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php _e( 'Payment Method:', 'woocommerce' ); ?>
<strong><?php echo $order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
<div class="clear"></div>
and also remove this
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>

displaying a gif in php code in wordpress

I recently took over a project for a client which is website built in wordpress and java script. The previous developer did not comment on their code so I have taken some time to decipher it.
The site uses woocommerce as the online shop. The client has requested that when a user makes a payment then the subsequent thank you screen displays an animated gif saying thank you.
Inserting the gif on the standard woocommerce checkout page is fine and works. The client however wants it displayed after the purchase on the thank you page which is created in code. The code is displayed below:
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p><?php esc_html_e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction.', "wp-experts" ); ?></p>
<p><?php
if ( is_user_logged_in() )
esc_html_e( 'Please attempt your purchase again or go to your account page.', "wp-experts" );
else
esc_html_e( 'Please attempt your purchase again.', "wp-experts" );
?></p>
<p>
<?php esc_html_e( 'Pay', "wp-experts" ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php esc_html_e( 'My Account', "wp-experts" ); ?>
<?php endif; ?>
</p>
<?php else : ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', "wp-experts" ), $order ); ?></p>
<ul class="order_details pull-left">
<li class="order">
<?php esc_html_e( 'Order Number:', "wp-experts" ); ?>
<strong><?php echo ''.$order->get_order_number(); ?></strong>
</li>
<li class="date">
<?php esc_html_e( 'Date:', "wp-experts" ); ?>
<strong><?php echo date_i18n( get_option( 'date_format' ), strtotime( $order->order_date ) ); ?></strong>
</li>
<li class="total">
<?php esc_html_e( 'Total:', "wp-experts" ); ?>
<strong><?php echo ''.$order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->payment_method_title ) : ?>
<li class="method">
<?php esc_html_e( 'Payment Method:', "wp-experts" ); ?>
<strong><?php echo ''.$order->payment_method_title; ?></strong>
</li>
<?php endif; ?>
</ul>
CLICK HERE TO GET STARTED!
<div class="clear"></div>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->payment_method, $order->id ); ?>
<?php do_action( 'woocommerce_thankyou', $order->id ); ?>
<p><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', esc_html__( 'Thank you. Your order has been received.', "wp-experts" ), null ); ?></p>
I have searched on google for how to display a gif in php.
The gif is uploaded on my serve in the images sub-directory of the theme
I have used ideas from stackoverflow like
$file = 'Camel-continuous-1.gif'
header('Content-type: image/gif');
readfile($file);
but this just crashes the web page. I placed this after the payment method line in the code above.
Any ideas? Thanks in advance
I am not able based on the code sniplet to tell where to insert it, but if you
<?php
//supposing the gif is in the same folder
$file = 'Camel-continuous-1.gif';
echo "<img src=\"".$file."\">";
?>
More short you could say it this way:
<?php='<img src="/gifs/Camel-continuous-1.gif" >'?>
Or more simple if you want to use the short open tag
<?='<img src="/gifs/Camel-continuous-1.gif" >'?>
have fun
Like #flomei I'm not sure I understand what you want, but if you just want the gif somewhere near the "Thank You" text you can just echo it in php. This will put it above the text "Thank you. Your order has been received":
<?php if ( $order->has_status( 'failed' ) : ?>
<?php // deleted your existing code. ?>
<?php else : ?>
<?php echo '<img src="Camel-continuous-1.gif"> ?>
<?php // more deleted code. ?>
<?php endif; ?>
this did not work for you because you mixed up Quotes. If you use double quotes to delimit a string you must either backslash it or use simple quotes inside.
In a similar way you must use double quotes if you delimit the string with simple quotes.
<?php
// this outputs a error
$file = '/uploads/2018/07/Camel-continuous-2.gif';
echo "<img width="251" height="243" src=\"".$file."\">";
?>
this will work for you on any php version. It is the clean method using backslashed quotes inside the quotes
<?php
$file = "/uploads/2018/07/Camel-continuous-2.gif";
echo "<img width=\"251\" height=\"243\" src=\"".$file."\">";
?>
also this will work for you on some php versions. (using double quotes inside simple quotes
<?php
$file = '/uploads/2018/07/Camel-continuous-2.gif';
echo '<img width="251" height="243" src="'.$file.'">';
?>
also this will work for you depending on your php version. using simple quotes inside double quotes
<?php
$file = "/uploads/2018/07/Camel-continuous-2.gif";
echo "<img width='251' height='243' src='".$file."'>";
?>

Uncommenting in Woocommerce template

I don't have much experience with PHP and was wondering if anyone could help me uncomment a few lines from the Woocommerce thankyou.php template that can be found here: https://github.com/woocommerce/woocommerce/blob/master/templates/checkout/thankyou.php . I need to remove the order details starting line 43-77:
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<li class="woocommerce-order-overview__order order">
<?php _e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="woocommerce-order-overview__date date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
</li>
<li class="woocommerce-order-overview__total total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php _e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
</li>
<?php endif; ?>
</ul>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
Thanks for your help!
This question is not clear. I think you want us to help you commenting a portion of code on that checkout/thankyou.php template, to remove some info from line 43 to 77…
So your template code will be:
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<div class="woocommerce-order">
<?php if ( $order ) : ?>
<?php if ( $order->has_status( 'failed' ) ) : ?>
<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed"><?php _e( 'Unfortunately your order cannot be processed as the originating bank/merchant has declined your transaction. Please attempt your purchase again.', 'woocommerce' ); ?></p>
<p class="woocommerce-notice woocommerce-notice--error woocommerce-thankyou-order-failed-actions">
<?php _e( 'Pay', 'woocommerce' ) ?>
<?php if ( is_user_logged_in() ) : ?>
<?php _e( 'My account', 'woocommerce' ); ?>
<?php endif; ?>
</p>
<?php endif; /* else: ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>
<ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">
<li class="woocommerce-order-overview__order order">
<?php _e( 'Order number:', 'woocommerce' ); ?>
<strong><?php echo $order->get_order_number(); ?></strong>
</li>
<li class="woocommerce-order-overview__date date">
<?php _e( 'Date:', 'woocommerce' ); ?>
<strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
</li>
<li class="woocommerce-order-overview__total total">
<?php _e( 'Total:', 'woocommerce' ); ?>
<strong><?php echo $order->get_formatted_order_total(); ?></strong>
</li>
<?php if ( $order->get_payment_method_title() ) : ?>
<li class="woocommerce-order-overview__payment-method method">
<?php _e( 'Payment method:', 'woocommerce' ); ?>
<strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
</li>
<?php endif; */ ?>
</ul>
<?php endif; ?>
<?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>
<?php else : ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>
<?php endif; ?>
</div>
I hope that is simply that…
Official Documentation: Template Structure + Overriding Templates via a Theme
Overriding templates in WooCommerce is quite simple, you just have to copy the template file you want to edit into the YOUR_THEME/woocommerce/ directory and edit/add/delete anything you want.
In your case you just have to copy the template file located in wp-content/plugins/woocommerce/templates/checkout/thankyou.php into wp-content/themes/YOUR_THEME/woocommerce/checkout and you're ready to go.
Be aware that you override the template files in child theme, otherwise after updating theme you will lose you changes.
Child theme creation procedure:
create a folder in themes directory and name it yourthemename-child
creat a style.css file and put this comment inside it
/*
Theme Name: Twenty Fifteen Child
Description: Twenty Fifteen Child Theme
Template: parent_theme_name
you can add other attributes here as well
*/

Remove word from Woocommerce count span in cart header

Does somebody know, where I can find the .php file in woocommerce, where I can remove the word "item" or "items" from the last span?
I've tried it with some jQuery Code but it only works when I load the page completely. When I click add to cart or remove from cart an item, the cart only reload in woocommerce without my .js file to remove the two words.
Can anybody help me?
Thank you
$('.count').html($('.count').html().replace(' items',''));
$('.count').html($('.count').html().replace(' item',''));
<a class="cart-contents" href="http://*****.de/warenkorb/" title="View your shopping cart">
<span class="amount">0,00 €</span>
<span class="count">0 items</span><!--Here I want to remove the Word items to show just the number-->
</a>
After a few days of breaking my head about this i've found a solution (I'm so happy and angry too because when you know the answer the solution is so easy).
First you have to find the file woocommerce/templates/cart/mini-cart.php to overwrite our function.
When you've found it you have to find following line:
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?></li>
After you've found it you have to insert following code under the line:
<?php
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" title="<?php _e( 'View your shopping cart', 'storefront' ); ?>">
<span class="count"><?php echo sprintf (_n( '%d', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?></span>
</a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
?>
Now you have to save the file and reload the page and put something in your cart (or remove) to update your cart. Know it should be done! :-)
If you want to add your price to the header too you also have to add above <span class="count"> following lines of code:
<span class="amount"><?php echo wp_kses_data( WC()->cart->get_cart_subtotal() ); ?></span>
If you have any questions you can always comment me…
To avoid the risk of these adjustments being overwritten if you update Storefront, you can also rewrite the function in your functions.php file like this:
if ( ! function_exists( 'storefront_cart_link' ) ) {
function storefront_cart_link() {
?>
<a class="cart-contents" href="<?php echo esc_url( wc_get_cart_url() ); ?>" title="<?php esc_attr_e( 'View your shopping cart', 'storefront' ); ?>">
<?php /* translators: %d: number of items in cart */ ?>
<?php echo wp_kses_post( WC()->cart->get_cart_subtotal() ); ?> <span class="count"><?php echo WC()->cart->get_cart_contents_count(); ?></span>
</a>
<?php
}
}

Categories