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_webservice_timeout.php
Created July 26, 2024 10:59
Increase DPD Portugal API timeout
<?php
/* Increase DPD Portugal API timeout */
add_filter( 'woo_dpd_portugal_webservice_timeout', function( $seconds ) {
return 60;
} );
@webdados
webdados / wc_ifthenpay_mbway_convertmb_expired_orders_email_subject.php
Created July 15, 2024 10:08
Change the MB WAY to Multibanco recover order email subject on Multibanco, MB WAY, Credit card, Payshop and Cofidis Pay (IfthenPay) for WooCommerce - PRO add-on
<?php
add_filter( 'wc_ifthenpay_mbway_convertmb_expired_orders_email_subject', function( $subject, $order ) {
return 'Enc. #' . $order->get_id() . ' - Última oportunidade para efetuares o pagamento!';
}, 10, 2 );
@webdados
webdados / swcbcf_validate_callback_{location}_{field-slug}.php
Created June 19, 2024 16:08
Using the swcbcf_validate_callback_{location}_{field-slug} filter to validate fields on the "Simple Custom Fields for WooCommerce Blocks Checkout" plugin
<?php
// Filter name: swcbcf_validate_callback_{location}_{field-slug}
// {location} can be contact, address or order
// {field-slug} is the field slug
// In this example we're validating a field that needs to be at least 5 chars long
add_filter( 'swcbcf_validate_callback_' . 'order' . '_' . 'how-did-you-get-to-know', function( $return, $value, $field ) {
if ( strlen( trim( $value ) ) < 5 ) {
return 'This field needs to be at least 5 characters long';
}
@webdados
webdados / swcbcf_get_custom_field.php
Created April 30, 2024 15:51
Helper functions for the Simple Custom Fields for WooCommerce Blocks Checkout plugin
<?php
/**
* Usage example for the "Simple Custom Fields for WooCommerce Blocks Checkout" plugin helper functions
* Get it at https://ptwooplugins.com/product/simple-custom-fields-for-woocommerce-blocks-checkout/
*/
// Get "fiscal-number" field from the "Contact information" section, on orders and users
$value = swcbcf_get_order_field( $order_id, 'other', 'fiscal-number' );
$value = swcbcf_get_user_field( $user_id, 'other', 'fiscal-number' );
@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 / 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 / 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;
}