Skip to content

Instantly share code, notes, and snippets.

View tankbar's full-sized avatar

Tankbar tankbar

View GitHub Profile
@tankbar
tankbar / wc-tracking-adtraction-thank-you-page
Last active February 20, 2024 15:31
Adtraction affiliate tracking on Thank you page
<?php
// Adtraction conversion tracking implementation
add_action( 'woocommerce_thankyou', 'adtraction_tracking', 60 );
function adtraction_tracking( $order_id ) {
$order = new WC_Order( $order_id );
$order_nr = $order->get_order_number();
$order_total_shipping = $order->get_total_shipping();
$order_total_ex_vat = $order->get_total() - $order->get_total_tax();
$order_total = $order_total_ex_vat - $order_total_shipping;
$order_email = get_user_meta( $order->user_id, 'billing_email', true );
@tankbar
tankbar / wp-google-tag-manager
Last active January 23, 2024 11:17
Add Google Tag Manager in WordPress with hooks and actions
<?php
/* ADD GTM TO HEAD AND BELOW OPENING BODY */
add_action('wp_head', 'google_tag_manager_head', 20);
function google_tag_manager_head() { ?>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
@tankbar
tankbar / wc-add-images-order-email-table.php
Created September 29, 2017 12:20 — forked from bekarice/wc-add-images-order-email-table.php
Add images to WooCommerce emails
// Edit order items table template defaults
function sww_add_wc_order_email_images( $table, $order ) {
ob_start();
$template = $plain_text ? 'emails/plain/email-order-items.php' : 'emails/email-order-items.php';
wc_get_template( $template, array(
'order' => $order,
'items' => $order->get_items(),
'show_download_links' => $show_download_links,
@tankbar
tankbar / functions.php
Created March 30, 2017 12:58
Add PDF to WooCommerce Order Email
<?php
add_filter( 'woocommerce_email_attachments', 'attach_terms_conditions_pdf_to_email', 10, 3);
function attach_terms_conditions_pdf_to_email ( $attachments , $id, $object ) {
$your_pdf_path = get_template_directory() . '/terms.pdf';
$attachments[] = $your_pdf_path;
return $attachments;
}
@tankbar
tankbar / functions.php
Created December 14, 2017 10:50
WooCommerce - Add GTIN/EAN meta field for product and product variations
/**
* Adding Custom GTIN Meta Field
* Save meta data to DB
*/
// add GTIN input field
add_action('woocommerce_product_options_inventory_product_data','woocom_simple_product_gtin_field', 10, 1 );
function woocom_simple_product_gtin_field(){
global $woocommerce, $post;
$product = new WC_Product(get_the_ID());
echo '<div id="gtin_attr" class="options_group">';
@tankbar
tankbar / functions.php
Created January 24, 2018 11:33
Add 4 important product identifiers Brand, MPN, UPC, EAN, GTIN to simple and variabel products
<?php
/*
Woocommerce additional product identifier fields
Add 4 important product identifiers Brand, MPN, UPC, EAN, GTIN to simple and variabel products required for sales channels
*/
// Simple Product Hooks
// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'wpmr_custom_general_fields' );
@tankbar
tankbar / package.json
Created April 4, 2022 13:19
Example package.json for gulpfile
{
"name": "example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
@tankbar
tankbar / gulpfile.js
Created April 4, 2022 13:17
Example gulpfile.js for WordPress theme writing to static folder
const { src, dest, parallel, series, watch } = require('gulp');
const concat = require('gulp-concat');
const sass = require('gulp-sass')(require('sass'));
const cleanCSS = require('gulp-clean-css');
const uglify = require('gulp-uglify-es').default;
const sourcemaps = require('gulp-sourcemaps');
const livereload = require('gulp-livereload');
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
@tankbar
tankbar / _buttons.scss
Created April 4, 2022 13:15
Example of SCSS for button
.btn,
.button,
button,
input[type=button],
input[type=submit] {
-webkit-appearance: none;
-moz-appearance: none;
cursor: pointer;
position: relative;
@tankbar
tankbar / functions-trustpilot.php
Created March 21, 2018 10:39
Trustpilot AFS product tracking in order confirmation mail for WooCommerce
add_action( 'woocommerce_email_after_order_table', 'add_trustpilot_afs_tracking', 20, 2 );
function add_trustpilot_afs_tracking( $order, $sent_to_admin ) {
if ( ! $sent_to_admin ) {
?>
<script type="application/json+trustpilot">
{
"recipientEmail": "<?php echo $order->billing_email; ?>",
"recipientName": "<?php echo $order->billing_first_name.' '. $order->billing_last_name; ?>",
"referenceId": "<?php echo $order->get_order_number(); ?>",
"products": [<?php