Skip to content

Instantly share code, notes, and snippets.

@bryceadams
bryceadams / wc-custom-meta-add.php
Created April 10, 2018 05:39
WC Custom Meta Adding
<?php
$order_id = 125;
add_post_meta( $order_id, 'payment_gateway_fee', 1.60 );
@bryceadams
bryceadams / gist:050d886159265d6f5e6dbce649552704
Last active April 14, 2022 20:59
Disable WooCommerce total spent / order count meta calculations
<?php
add_filter( 'get_user_metadata', 'mtkdocs_filter_user_metadata', 10, 4 );
function mtkdocs_filter_user_metadata( $value, $object_id, $meta_key, $single ) {
// Check if it's one of the keys we want to filter
if ( in_array( $meta_key, array( '_money_spent', '_order_count' ) ) ) {
// Return 0 so WC doesn't try calculate it
return 0;
}
// Default
@bryceadams
bryceadams / change.php
Created June 24, 2017 02:55
Automatically change 'pending cancel' subscriptions to 'cancelled'
<?php
/**
* Move pending cancellation to cancelled automatically.
*/
function metorik_custom_cancel_function( $subscription, $new_status, $old_status ) {
if ( 'pending-cancel' === $new_status ) {
$subscription->update_status( 'cancelled' );
}
<?php
// Remove that PHP above if you are having errors come up after saving the file.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
@bryceadams
bryceadams / metorik_stop_multiple_coupons.php
Last active March 17, 2022 13:23
Plugin to only allow individual use coupons in WooCommerce, even if they have not been set as such.
<?php
/*
Plugin Name: Stop Multiple WooCommerce Coupons
Plugin URI: https://metorik.com
Description: Only allow individual use coupons in WooCommerce, even if they have not been set as such.
Version: 1.0.0
Author: Bryce Adams (Metorik)
Author URI: https://metorik.com
Text Domain: stop-multiple-woocommerce-coupons-metorik
*/
.shipping-calculator-form {
display: block !important;
}
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_false' );
add_filter( 'woocommerce_ship_to_different_address_checked', '__return_true' );
<?php
/**
* Autocomplete Paid Orders (WC 2.2+)
*/
add_filter( 'woocommerce_payment_complete_order_status', 'bryce_wc_autocomplete_paid_paypal_orders' );
function bryce_wc_autocomplete_paid_paypal_orders( $order_status, $order_id ) {
$order = wc_get_order( $order_id );
if ( $order->payment_method == 'paypal' ) {
if ( $order_status == 'processing' && ( $order->status == 'on-hold' || $order->status == 'pending' || $order->status == 'failed' ) ) {
127.0.0.1 woo3dprint.dev