Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / invoicexpress_woocommerce_document_item.php
Last active June 1, 2024 08:58
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 (sku)
$item_data['name'] = 'whatever';
// Or add something to its description (product title)
$item_data['description'] .= 'whatever';
// And return it
return $item_data;
@webdados
webdados / woocommerce_nav_admin_orders_first.php
Last active April 14, 2021 12:54
Orders as the first submenu item on the WooCommerce WP-Admin menu
<?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 March 8, 2021 17:48
Get AT Code 2 minutes after issuing Delivery Note with Invoicing with InvoiceXpress for WooCommerce
<?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 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 ) {