Skip to content

Instantly share code, notes, and snippets.

Avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / add_quantcast_choice_headar.php
Created Jul 4, 2022
Add the new (June 2022) Quantcast Choice code to your WordPress website header
View add_quantcast_choice_headar.php
<?php
add_action( 'wp_head', array( $this, 'quantcast_choice_enable_action' ), function() {
?>
<!-- Quantcast Choice. Consent Manager Tag v2.0 (for TCF 2.0) -->
<script type="text/javascript" async=true>
(function() {
var host = window.location.hostname;
var element = document.createElement('script');
var firstScript = document.getElementsByTagName('script')[0];
var url = 'https://cmp.quantcast.com'
@webdados
webdados / ga_tcf2.js
Last active Jun 24, 2022
Google Analytics with TCF v2.0 support
View ga_tcf2.js
/* Need help? Hire us: https://www.webdados.pt/contactos/ */
//We need to wait for the page to be ready, or else the Consent platform may not be loaded yet, and we'll fire the pageview earlier than we should
window.onload = function() {
var google_analytics_id = 'UA-111111-01'; //Replace with yours
//Prepare the data layer
window.dataLayer = window.dataLayer || []
//gtag function
function gtag() {
dataLayer.push(arguments);
@webdados
webdados / ifthen_send_email_instructions.php
Created Mar 22, 2022
Remove IfthenPay payment instructions from some WooCommerce emails
View ifthen_send_email_instructions.php
<?php
add_filter( 'multibanco_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'mbway_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'creditcard_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
add_filter( 'payshop_ifthen_send_email_instructions', 'my_multibanco_ifthen_send_email_instructions', 10, 5 );
function my_multibanco_ifthen_send_email_instructions( $send, $order, $sent_to_admin, $plain_text, $email ) {
$emails_to_remove = array(
'customer_completed_order',
@webdados
webdados / flatsome_live_search_relevanssi_search_ok.php
Last active Jan 5, 2022
Make Flatsome live search work with Relevanssi
View flatsome_live_search_relevanssi_search_ok.php
<?php
add_filter( 'relevanssi_search_ok', 'flatsome_live_search_relevanssi_search_ok' );
function flatsome_live_search_relevanssi_search_ok( $search_ok ) {
if ( is_ajax() && isset( $_GET['action'] ) && trim( $_GET['action'] ) == 'flatsome_ajax_search_products' ) {
return true;
}
return $search_ok;
}
@webdados
webdados / include_kk_categories.php
Created Jun 4, 2021
Include only certain products on the KuantoKusta WooCommerce feed
View include_kk_categories.php
<?php
//Get the plugin from https://www.webdados.pt/wordpress/plugins/feed-kuantokusta-para-woocommerce/
add_filter( 'kuantokusta_product_node_show', 'my_include_kk_categories', 10, 2 );
add_filter( 'kuantokusta_variation_node_show', 'my_include_kk_categories', 10, 2 );
function include_kk_categories( $show, $product ) {
//If not show, we don't neeed to process the item
if ( $show ) {
//Init as false
$show = false;
//Product categories IDs to include in the feed
@webdados
webdados / invoicexpress_woocommerce_document_item.php
Created Apr 20, 2021
Manipulate item data before adding it to a InvoiceXpress document on the "Invoicing with InvoiceXpress for WooCommerce – Pro" plugin
View invoicexpress_woocommerce_document_item.php
<?php
add_filter( 'invoicexpress_woocommerce_document_item', function( $item_data, $item, $product, $order_object, $document_type, $args ) {
//Do whatever you want with the $item_data array, for example, change its reference or description
$item_data['name'] = 'whatever';
//Or add somthing to its description
$item_data['description'] .= 'whatever';
//And return it
return $item_data;
}, 10, 6 );
@webdados
webdados / woocommerce_nav_admin_orders_first.php
Last active Apr 14, 2021
Orders as the first submenu item on the WooCommerce WP-Admin menu
View woocommerce_nav_admin_orders_first.php
<?php
add_filter( 'custom_menu_order', 'woocommerce_nav_admin_orders_first' );
function woocommerce_nav_admin_orders_first( $menu_order ) {
if ( is_admin() ) {
global $submenu;
if ( isset( $submenu['woocommerce'] ) && is_array( $submenu['woocommerce'] ) ) {
$temp = array();
//Add orders as first
foreach ( $submenu['woocommerce'] as $submenu_item ) {
if ( isset( $submenu_item[2] ) && $submenu_item[2] == 'edit.php?post_type=shop_order' ) {
@webdados
webdados / invoicexpress_woocommerce_fetch_at_code.php
Created Mar 8, 2021
Get AT Code 2 minutes after issuing Delivery Note with Invoicing with InvoiceXpress for WooCommerce
View invoicexpress_woocommerce_fetch_at_code.php
<?php
/* Get AT Code 2 minutes after issuing Delivery Note - WordPress crons need to be running properly */
add_action( 'invoicexpress_woocommerce_after_document_finish', function( $order_id, $type ) {
if ( $type == 'transport_guide' ) {
$minutes = 2;
wp_schedule_single_event( time() + ( $minutes * 60 ), 'invoicexpress_woocommerce_fetch_at_code', array( $order_id ) );
}
}, 10, 2 );
@webdados
webdados / shop_as_client_autocomplete_limit.php
Created Feb 23, 2021
Return 10 users and 10 order (20 results) to the Shop As Client Pro Add-on autocomplete feature
View shop_as_client_autocomplete_limit.php
<?php
//Return 10 users and 10 order (20 results) to the Shop As Client Pro Add-on autocomplete feature
add_filter( 'shop_as_client_autocomplete_limit', function( $limit ) {
return 10;
}
@webdados
webdados / woo_dpd_portugal_email_tracking_hook_action.php
Created Dec 23, 2020
Show "DPD Portugal for WooCommerce" email tracking information before the customer details instead before order details
View woo_dpd_portugal_email_tracking_hook_action.php
<?php
add_filter( 'woo_dpd_portugal_email_tracking_hook_action', function( $action ) {
return 'woocommerce_email_customer_details';
} );
add_filter( 'woo_dpd_portugal_email_tracking_hook_priority', function( $priority ) {
return 1;
} );