Skip to content

Instantly share code, notes, and snippets.

View webdados's full-sized avatar

Marco Almeida webdados

View GitHub Profile
@webdados
webdados / woocommerce_checkout_update_order_meta.php
Created June 24, 2020 09:47
Add WooCommerce order meta if there's a product on backorder
<?php
add_action( 'woocommerce_checkout_update_order_meta', function( $order_id, $data ) {
foreach ( WC()->cart->cart_contents as $item ) {
if ( $item['data']->is_on_backorder() ) {
$order = wc_get_order( $order_id );
$order->update_meta_data( '_has_backorder_product', 1 );
$order->save();
break;
}
}
@webdados
webdados / invoicexpress_woocommerce_exccat_exclude_types.php
Last active June 8, 2020 17:11
Exclude document types from invoicing exclusions on "Invoicing with InvoiceXpress for WooCommerce - Exclude categories/tags extension"
<?php
add_filter( 'invoicexpress_woocommerce_exccat_exclude_types', function( $exclude_types ) {
//Return an array of document types where all items should be invoiced and not excluded by category or tag
return array(
'transport_guide'
);
} );
@webdados
webdados / woocommerce_get_european_union_countries_after_wc4.php
Last active April 7, 2020 20:56
Workaround for WooCommerce get_european_union_countries( 'eu_vat' ) after WooCommerce 4.0.0
<?php
//See here why this is needed: https://github.com/woocommerce/woocommerce/issues/26105
function woocommerce_get_european_union_countries_after_wc4( $type = '' ) {
$countries = WC()->countries->get_european_union_countries();
if ( 'eu_vat' === $type ) {
$countries[] = 'MC';
$countries[] = 'IM';
$countries[] = 'GB'; //Great Britain is still part of the EU VAT zone
}
return $countries;
@webdados
webdados / remove_wp_54_favicon.php
Last active December 29, 2021 20:42
Do not show WordPress 5.4 default WP blue favicon
<?php
//Inspiration: https://gist.github.com/florianbrinkmann/a879099f3d28c5e1d64f2aeea042becf
add_action( 'do_faviconico', function() {
//Check for icon with no default value
if ( $icon = get_site_icon_url( 32 ) ) {
//Show the icon
wp_redirect( $icon );
} else {
//Show nothing
header( 'Content-Type: image/vnd.microsoft.icon' );
@webdados
webdados / woo_dpd_portugal_issue_label.php
Last active March 11, 2025 13:33
Create a DPD Portugal shipping label programmatically with the "DPD Portugal for WooCommerce" WordPress plugin
<?php
// You need this plugin: https://www.webdados.pt/wordpress/plugins/dpd-portugal-para-woocommerce-wordpress/
// Step 2 (ok) - Monitor the result (success) and do whatver you want with it - Needs to be set before running it
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 / remove_acores_madeira_pickup_points.php
Last active February 17, 2020 19:09
Remove Açores and Madeira pickup points from Portugal Chronopost Pickup network for WooCommerce and/or Portugal VASP Expresso Kios network for WooCommerce
<?php
//Uncomment next line to activate for Chronopost
//add_filter( 'cppw_available_points', 'remove_acores_madeira_pickup_points', 10, 2 );
//Uncomment next line to activate for Chronopost
//add_filter( 'pvkw_available_points', 'remove_acores_madeira_pickup_points', 10, 2 );
//The filter function
function remove_acores_madeira_pickup_points( $points, $postcode ) {
foreach ( $points as $key => $point ) {
@webdados
webdados / delete_all_comments.php
Created February 5, 2020 09:22
Delete all comments from a WordPress post
<?php
/*
- Save this PHP file to the root of your WordPress website
- Log in as Administrator
- Change the post ID on line 13
- Call the PHP file it directly on your borwser
*/
require('./wp-load.php');
@webdados
webdados / woocommerce_email_customer_details.php
Created January 14, 2020 15:58
Remove addresses from WooCommerce emails
<?php
remove_action( 'woocommerce_email_customer_details', array( WC_Emails::instance() , 'email_addresses' ), 20 );
@webdados
webdados / wc_customer_has_capability_override_pay_for_order.php
Created January 8, 2020 13:16
Allow any user (logged in or not) to pay for any other user (or guest) WooCommerce order
<?php
add_filter( 'user_has_cap', 'wc_customer_has_capability_override_pay_for_order', 15, 3 );
function wc_customer_has_capability_override_pay_for_order( $allcaps, $caps, $args ) {
if ( isset( $caps[0] ) ) {
switch ( $caps[0] ) {
case 'pay_for_order':
$allcaps['pay_for_order'] = true;
break;
}
}
@webdados
webdados / shop_as_client_pro_search_order_statuses.php
Created January 7, 2020 15:03
Limit the order statuses where the customer is searched (if not found as a user) on Shop as Client PRO
<?php
/* Add this to you (child-)theme functions.php file */
add_filter( 'shop_as_client_pro_search_order_statuses', 'my_shop_as_client_pro_search_order_statuses' );
function my_shop_as_client_pro_search_order_statuses( $statuses ) {
//Only for Processing and Completed orders
$statuses = array( 'processing', 'completed' );
//Return
return $statuses;