Skip to content

Instantly share code, notes, and snippets.

Avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / ivoicexpress_vat_field_woocommerce.php
Last active Nov 23, 2020
Customize the "Invoicing with InvoiceXpress for WooCommerce" VAT field
View ivoicexpress_vat_field_woocommerce.php
<?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 Nov 19, 2020
Create a DPD Portugal return label programmatically, right after the shipping label, with the "DPD Portugal for WooCommerce" WordPress plugin
View woo_dpd_portugal_issue_return.php
<?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 Nov 13, 2020
Email to admin when WordPress lost password is requested
View lostpassword_post.php
<?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 Oct 27, 2020
Add InvoiceXpress documents to WooCommerce order list
View woocommerce_ixpro_invoice_order_list.php
<?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 Oct 7, 2020
Show all options on the first select for a WooCommerce variable products even if not available
View woocommerce_variation_has_changed.js
(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 Sep 28, 2020
Change NIF field priority on the WooCommerce checkout
View woocommerce_nif_field_priority.php
<?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 Sep 22, 2020
First and last day of the month as "Magic coupon" HTML message
View magic_coupon_html_message_replace_tags.php
<?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;
}
@webdados
webdados / sanitize_file_name.php
Created Sep 10, 2020
Sanitize WordPress uploaded file names
View sanitize_file_name.php
<?php
add_filter( 'sanitize_file_name', 'my_sanitize_file_name' );
function my_sanitize_file_name( $filename ) {
$original_chars = array(
'/А/','/Б/','/В/','/Г/', // cyrillic alphabet
'/Д/','/Е/','/Ж/','/З/','/И/',
'/Й/','/К/','/Л/','/М/','/Н/',
'/О/','/П/','/Р/','/С/','/Т/',
@webdados
webdados / custom_prevent_barcode.php
Created Sep 1, 2020
Only show the WooCommerce Barcode on processing (and completed) orders
View custom_prevent_barcode.php
<?php
//Add this to your (child-)theme functions.php file
//Before woocommerce_email_after_order_table 1 and woocommerce_order_details_after_order_table 1, because on the woocommerce_order_barcodes_display_barcode filter we don't have access to the $order object
add_action( 'woocommerce_email_after_order_table', 'custom_prevent_barcode', -1, 1 );
add_action( 'woocommerce_order_details_after_order_table', 'custom_prevent_barcode', -1, 1 );
function custom_prevent_barcode( $order ) {
$allowed_statuses = array(
'processing',
@webdados
webdados / remove_unnecessary_scripts_and_styles.css.php
Created Jul 31, 2020
Remove WordPress unnecessary scripts and styles that some shortcodes load on every page
View remove_unnecessary_scripts_and_styles.css.php
<?php
add_action( 'wp_enqueue_scripts', 'my_remove_unnecessary_scripts_and_styles', PHP_INT_MAX );
function my_remove_unnecessary_scripts_and_styles() {
//Remove Mapbox styles and scripts
global $post;
if ( ! ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'wp_mapbox_gl_js' ) ) ) {
wp_dequeue_style( 'mapbox_gl_js_css' );
wp_dequeue_style( 'mapbox_gl_js_geocoder_css' );
wp_dequeue_style( 'mapbox_gl_js_directions_css' );
wp_dequeue_style( 'wp-mapbox-gl-js' );
You can’t perform that action at this time.