Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Updating knowledgebase...

Luis CasperBraske

🤓
Updating knowledgebase...
View GitHub Profile
@CasperBraske
CasperBraske / functions.php
Last active Nov 6, 2020
Remove country and city fields from shipping calculator and disable "calculate shipping" toggle non-sense.
View functions.php
<?php
add_filter( 'woocommerce_shipping_calculator_enable_country', '__return_false' );
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );
@CasperBraske
CasperBraske / functions.php
Last active Jun 1, 2020
Disable all Dokan Pro modules at once.
View functions.php
<?php
add_action('init', function(){
dokan_pro()->module->deactivate_modules(
[
'booking',
'color_scheme_customizer',
'elementor',
'export_import',
'follow_store',
@CasperBraske
CasperBraske / functions.php
Last active Dec 5, 2019
[WooCommerce BR] Woocommerce - show discount percentage
View functions.php
<?php
add_filter( 'woocommerce_sale_flash', function( $string, $post, $product ) {
$regular_price = (float) $product->get_regular_price();
$sale_price = (float) $product->get_price();
$discount = round( 100 - ( $sale_price / $regular_price * 100 ), 1 );
return sprintf( '<span class="onsale">%s%%</span>', $discount );
@CasperBraske
CasperBraske / functions.php
Last active Dec 5, 2019
Add order meta to child orders in WC Marketplace
View functions.php
<?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 );
@CasperBraske
CasperBraske / functions.php
Created Sep 11, 2019
[WooCommerce BR] Restrict coupon from being used bt its author
View functions.php
<?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 ) {
@CasperBraske
CasperBraske / by-email.sql
Last active Aug 30, 2019
[WooCommerce BR] Get orders from user by ID or e-mail
View by-email.sql
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
@CasperBraske
CasperBraske / functions.php
Created Jun 10, 2019
[WooCommerce BR] Keep shipping fields from being fed with billing values:
View functions.php
<?php
function wcbr_disable_copy_shipping_from_billing_fields( $default, $input ){
if( 0 === stripos($input, 'shipping_') ){
$default = '';
}
return $default;
@CasperBraske
CasperBraske / functions.php
Created Jun 7, 2019
Allow coupon only for customers who already have placed orders.
View functions.php
<?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 ) {
@CasperBraske
CasperBraske / functions.php
Last active Apr 4, 2019
Disable package splitting in Dokan Pro
View functions.php
<?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 );
@CasperBraske
CasperBraske / functions.php
Last active Mar 19, 2019
Change new user notification e-mail body.
View functions.php
<?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;
You can’t perform that action at this time.