Skip to content

Instantly share code, notes, and snippets.

View luiseduardobraschi's full-sized avatar
🤓
Updating knowledgebase...

Luis Braschi luiseduardobraschi

🤓
Updating knowledgebase...
View GitHub Profile
@luiseduardobraschi
luiseduardobraschi / functions.php
Last active December 5, 2019 03:14
Add order meta to child orders in WC Marketplace
<?php
add_action( 'wcmp_checkout_update_order_meta', function( $vendor_order_id, $args ){
$parent_order = wc_get_order( $args['order_id'] );
$child_order = wc_get_order( $vendor_order_id );
foreach( $parent_order->get_meta_data() as $meta ){
$child_order->update_meta_data( $meta->key, $meta->value );
@luiseduardobraschi
luiseduardobraschi / functions.php
Created September 11, 2019 16:35
[WooCommerce BR] Restrict coupon from being used bt its author
<?php
add_filter('woocommerce_coupon_is_valid', 'wcbr_coupon_is_valid', 10, 2);
function wcbr_coupon_is_valid( $valid, $coupon ) {
global $woocommerce;
$customer_id = $woocommerce->customer->get_id();
$coupon_author_id = get_post_field( 'post_author', $coupon->get_id() );
if ( $customer_id === $coupon_author_id ) {
@luiseduardobraschi
luiseduardobraschi / by-email.sql
Last active August 30, 2019 22:46
[WooCommerce BR] Get orders from user by ID or e-mail
SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_users AS users ON users.user_email = 'EMAIL_YOU_WANT'
INNER JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id
WHERE 1=1
AND wp_postmeta.meta_key = '_customer_user'
AND wp_postmeta.meta_value = users.ID
AND wp_posts.post_type = 'shop_order'
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC
@luiseduardobraschi
luiseduardobraschi / functions.php
Created June 10, 2019 22:43
[WooCommerce BR] Keep shipping fields from being fed with billing values:
<?php
function wcbr_disable_copy_shipping_from_billing_fields( $default, $input ){
if( 0 === stripos($input, 'shipping_') ){
$default = '';
}
return $default;
@luiseduardobraschi
luiseduardobraschi / functions.php
Created June 7, 2019 02:37
Allow coupon only for customers who already have placed orders.
<?php
add_filter('woocommerce_coupon_is_valid', 'wcbr_coupon_is_valid', 10, 2);
function wcbr_coupon_is_valid( $valid, $coupon ) {
global $woocommerce;
$customer = $woocommerce->customer;
if ( wc_get_customer_order_count( $customer->get_id() ) < 1 ) {
@luiseduardobraschi
luiseduardobraschi / functions.php
Last active April 4, 2019 15:56
Disable package splitting in Dokan Pro
<?php
remove_filter( 'woocommerce_cart_shipping_packages', 'dokan_custom_split_shipping_packages' );
remove_filter( 'woocommerce_shipping_package_name', 'dokan_change_shipping_pack_name' );
remove_action( 'woocommerce_checkout_create_order_shipping_item', 'dokan_add_shipping_pack_meta' );
add_filter( 'woocommerce_shipping_methods', function($methods){
unset( $methods['dokan_vendor_shipping'] );
return $methods;
}, 11 );
@luiseduardobraschi
luiseduardobraschi / functions.php
Last active March 19, 2019 04:00
Change new user notification e-mail body.
<?php
add_filter( 'wp_new_user_notification_email', 'gist_change_new_user_message', 10, 3 );
function gist_change_new_user_message( $wp_new_user_notification_email, $user, $blogname ){
$wp_new_user_notification_email['message'] = "This is the new mail body.\r\n\r\n"";
return $wp_new_user_notification_email;
@luiseduardobraschi
luiseduardobraschi / functions.php
Last active December 8, 2020 19:06
Remover o campo "sexo" do checkout do WooCommerce com Extra Checkout Fields for Brazil.
<?php
add_filter( 'woocommerce_billing_fields', function( $fields ){
unset( $fields['billing_sex'] );
return $fields;
});
@luiseduardobraschi
luiseduardobraschi / functions.php
Created October 12, 2018 01:07
Dias a mais para produtos sob encomenda.
<?php
add_filter('woocommerce_correios_shipping_additional_time', function($additional_time, $package){
$has_outofstock_item = false;
foreach( $package['contents'] as $item ) {
if ( 'onbackorder' === wc_get_product($item['product_id'])->get_stock_status() ){
$has_outofstock_item = true;
break;
@luiseduardobraschi
luiseduardobraschi / readme.md
Last active October 8, 2018 05:48
[WP BR] Remove out of stock product URL and redirect single to home