Skip to content

Instantly share code, notes, and snippets.

Avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / include_kk_categories.php
Created Jun 4, 2021
Include only certain products on the KuantoKusta WooCommerce feed
View include_kk_categories.php
<?php
//Get the plugin from https://www.webdados.pt/wordpress/plugins/feed-kuantokusta-para-woocommerce/
add_filter( 'kuantokusta_product_node_show', 'my_include_kk_categories', 10, 2 );
add_filter( 'kuantokusta_variation_node_show', 'my_include_kk_categories', 10, 2 );
function include_kk_categories( $show, $product ) {
//If not show, we don't neeed to process the item
if ( $show ) {
//Init as false
$show = false;
//Product categories IDs to include in the feed
@webdados
webdados / invoicexpress_woocommerce_document_item.php
Created Apr 20, 2021
Manipulate item data before adding it to a InvoiceXpress document on the "Invoicing with InvoiceXpress for WooCommerce – Pro" plugin
View invoicexpress_woocommerce_document_item.php
<?php
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;
}, 10, 6 );
@webdados
webdados / woocommerce_nav_admin_orders_first.php
Last active Apr 14, 2021
Orders as the first submenu item on the WooCommerce WP-Admin menu
View woocommerce_nav_admin_orders_first.php
<?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 Mar 8, 2021
Get AT Code 2 minutes after issuing Delivery Note with Invoicing with InvoiceXpress for WooCommerce
View invoicexpress_woocommerce_fetch_at_code.php
<?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 Feb 23, 2021
Return 10 users and 10 order (20 results) to the Shop As Client Pro Add-on autocomplete feature
View shop_as_client_autocomplete_limit.php
<?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 Dec 23, 2020
Show "DPD Portugal for WooCommerce" email tracking information before the customer details instead before order details
View woo_dpd_portugal_email_tracking_hook_action.php
<?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 Dec 14, 2020
Limit the reference range on the "Payment Multicaixa (ProxyPay gateway) for WooCommerce" WordPress plugin by webdados.pt
View multicaixa_create_ref_min_max.php
<?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 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'];