Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / shop_as_client_autocomplete_limit.php
Created February 23, 2021 22:06
Return 10 users and 10 order (20 results) to the Shop As Client Pro Add-on autocomplete feature
<?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 December 23, 2020 10:57
Show "DPD Portugal for WooCommerce" email tracking information before the customer details instead before order details
<?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;
} );
@webdados
webdados / multicaixa_create_ref_min_max.php
Created December 14, 2020 13:33
Limit the reference range on the "Payment Multicaixa (ProxyPay gateway) for WooCommerce" WordPress plugin by webdados.pt
<?php
add_filter( 'multicaixa_create_ref_min', function( $value ) {
return 0;
} );
add_filter( 'multicaixa_create_ref_max', function( $value ) {
return 333333333;
} );
@webdados
webdados / ivoicexpress_vat_field_woocommerce.php
Last active November 23, 2020 18:02
Customize the "Invoicing with InvoiceXpress for WooCommerce" VAT field
<?php
//We hook woocommerce_checkout_fields at 50, so this needs to be at least 51
add_filter( 'woocommerce_checkout_fields', 'ix_vat_woocommerce_checkout_fields', 51 );
function ix_vat_woocommerce_checkout_fields( $fields ) {
//Change label - originally __( 'VAT number', 'woo-billing-with-invoicexpress' )
$fields['billing']['billing_VAT_code']['label'] = 'My VAT label';
//Change priority - originally 120, 31 is after company
$fields['billing']['billing_VAT_code']['priority'] = 31;
//Make it half size and on the left
$fields['billing']['billing_VAT_code']['class'] = array( 'form-row', 'form-row-first' );
@webdados
webdados / woo_dpd_portugal_issue_return.php
Created November 19, 2020 14:38
Create a DPD Portugal return label programmatically, right after the shipping label, with the "DPD Portugal for WooCommerce" WordPress plugin
<?php
//You need this plugin: https://www.webdados.pt/wordpress/plugins/dpd-portugal-para-woocommerce-wordpress/
//Monitor the "issue label" result (success) and do whatver you want with it - Needs to be set before running "woo_dpd_portugal_issue_label"
add_action( 'woo_dpd_portugal_label_issued', function( $order_id ) {
$order = wc_get_order( $order_id );
echo 'Label issued for order '.$order_id.' on '.$order->get_meta( '_woo_dpd_portugal_label_issued' ).'<br/>';
echo 'Tracking number(s): '.implode( ' / ', $order->get_meta( '_woo_dpd_portugal_tracking_number' ) ).'<br/>';
echo 'Label PDF URL: '.$order->get_meta( '_woo_dpd_portugal_pdf_url' ).'<br/>';
@webdados
webdados / lostpassword_post.php
Created November 13, 2020 09:08
Email to admin when WordPress lost password is requested
<?php
/* Email to admin when WordPress lost password is requested */
add_action( 'lostpassword_post', 'my_lostpassword_post', 10, 2 );
function my_lostpassword_post( $errors, $user_data ) {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
@webdados
webdados / woocommerce_ixpro_invoice_order_list.php
Created October 27, 2020 09:55
Add InvoiceXpress documents to WooCommerce order list
<?php
add_filter( 'manage_edit-shop_order_columns', 'woocommerce_ixpro_invoice_order_list_column_header' );
function woocommerce_ixpro_invoice_order_list_column_header( $columns ) {
$columns['ixpro_docs'] = __( 'InvoiceXpress', 'webdados-toolbox' );
return $columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'woocommerce_ixpro_invoice_order_list_column_value' );
function woocommerce_ixpro_invoice_order_list_column_value( $column ) {
global $post;
if ( 'ixpro_docs' === $column ) {
@webdados
webdados / woocommerce_variation_has_changed.js
Created October 7, 2020 15:33
Show all options on the first select for a WooCommerce variable products even if not available
(function($) {
$( '.variations_form' ).on( 'woocommerce_variation_has_changed', function( ev ) {
$( this ).find( '.variations select' ).each( function( index, el ) {
//Get the first select current value
var value = $( el ).val();
//Get the original HTML from .data( 'attribute_html' ) and replace it again on the element.
$( el ).html( $( el ).data( 'attribute_html' ) );
//Then set the value again
$( el ).val( value );
@webdados
webdados / woocommerce_nif_field_priority.php
Created September 28, 2020 12:34
Change NIF field priority on the WooCommerce checkout
<?php
//Change NIF field priority
add_filter( 'woocommerce_nif_field_priority', 'woocommerce_nif_field_priority' );
function woocommerce_nif_field_priority( $priority ) {
//Default is 120
return 25;
}
@webdados
webdados / magic_coupon_html_message_replace_tags.php
Created September 22, 2020 12:18
First and last day of the month as "Magic coupon" HTML message
<?php
add_filter( 'magic_coupon_html_message_replace_tags', 'bf_magic_coupon_html_message_replace_tags' );
function bf_magic_coupon_html_message_replace_tags( $tags ) {
$tags['date_first_day_month'] = date_i18n( get_option( 'date_format' ), strtotime( date_i18n( 'Y-m-01' ) ) );
$tags['date_last_day_month'] = date_i18n( get_option( 'date_format' ), strtotime( date_i18n( 'Y-m-t' ) ) );
return $tags;
}