Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / woo_dpd_portugal_update_order_tracking_information.php
Last active April 25, 2024 09:59
Update order objects tracking information on DPD Portugal for WooCommerce
<?php
/**
* Run action each time a object tracking information is updated (not recommended unless you need to diferentiate each object)
*
* @param int $order_id The order ID
* @param string $tracking_number The object tracking number
* @param array $tracking_information An array will all objects traking information (the key is the tracking number)
* @param bool $programmatically If the udpate was triggered programmatically
**/
@webdados
webdados / woo_dpd_portugal_get_token.php
Created April 5, 2024 15:30
Get a token for the DPD Portugal REST AI from the "DPD Portugal for WooCommerce" plugin
<?php
$token = apply_filters( 'woo_dpd_portugal_get_token', null );
if ( $token['success'] ) {
// Do your thing with $token['token']
var_dump( $token['token'] );
}
@webdados
webdados / shop_as_client_pro_customer_data.php
Last active April 2, 2024 10:55
How to add custom fields to the Shop as Client PRO add-on ajax call - Classic Checkout
<?php
/* Add this to you (child-)theme functions.php file, on a (mu-)plugin or with a plugin like Code Snippets https://wordpress.org/plugins/code-snippets/ */
/* This only works with the classic checkout */
add_filter( 'shop_as_client_pro_customer_data', 'my_shop_as_client_pro_customer_data', 10, 3 );
function my_shop_as_client_pro_customer_data( $data, $customer = null, $order = null ) {
//Are we getting a "customer" object?
if ( $customer ) {
//Custom checkout field with id "billing_xpto"
@webdados
webdados / register_nav_menus.php
Created March 19, 2024 17:37
How to create classic menu locations on WordPress
<?php
/**
* Register menu locations - Put this on your (child-)theme functions.php file or use a code snippets plugin
*/
add_action( 'after_setup_theme', function() {
register_nav_menus(
array(
// One line per location
'top_menu' => 'Top menu',
'footer_menu' => 'Footer menu',
@webdados
webdados / ga_tcf2.js
Last active February 23, 2024 08:45
Google Analytics with TCF v2.0 support
/* 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 / product_assembly_cost_filter.php
Created February 14, 2024 12:45
Filter to override/set the service cost on runtime on the Product Assembly / Gift Wrap / … Cost for WooCommerce plugin
<?php
/* Set the product assembly cost to 5 on two specific products - https://wordpress.org/plugins/product-assembly-cost/ */
add_filter( 'product_assembly_cost', function( $cost, $product_or_variation ) {
if ( $product_or_variation->get_id() == 17536 || $product_or_variation->get_id() == 16932 ) { // Set whatever condition you want here
$cost = 5;
}
return $cost;
}, 10, 2 );
@webdados
webdados / woocommerce_get_order_note.php
Created January 16, 2024 15:11
Show user email on WooCommerce order notes
<?php
/* Also show the user email on the WooCommerce order notes */
add_filter( 'woocommerce_get_order_note', function( $note, $data ) {
if ( $note['added_by'] !== 'system' ) {
$note['added_by'] .= ' (' . $data->comment_author_email . ')';
}
return $note;
}, 10, 2 );
@webdados
webdados / moloni_store_at_code.php
Created January 5, 2024 12:45
Get and store the AT Code after Moloni creates a "Bill of Lading" (Guia de Transporte) on WooCommerce
<?php
add_filter( 'moloni_after_close_document', 'moloni_store_at_code' );
/* Store Moloni AT Code - https://wordpress.org/support/topic/codigo-at-no-meta-da-encomenda/ */
function moloni_store_at_code( $document_builder ) {
// Only for "Guias de Transporte"
if ( $document_builder->documentType != 'billsOfLading' ) {
return $document_builder;
}
@webdados
webdados / invoicexpress_woocommerce_document_item.php
Last active December 31, 2023 11:53
Manipulate item data before adding it to a InvoiceXpress document on the "Invoicing with InvoiceXpress for WooCommerce – Pro" plugin
<?php
// Change item properties
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;
@webdados
webdados / disable_auth.php
Created September 15, 2023 11:30
Disable WordPress authentication entirely
<?php
add_filter( 'authenticate', function( $user, $username ) {
return new WP_Error( 'foo', 'This account is disabled' );
}, 10, 2 );