Skip to content

Instantly share code, notes, and snippets.

View maddisondesigns's full-sized avatar

Anthony Hortin maddisondesigns

View GitHub Profile
@maddisondesigns
maddisondesigns / functions.php
Created December 13, 2024 08:59
Increase the number of orders shown on the Orders page in My Acccount within WooCommerce
/**
* Increase the number of orders shown on the Orders page in My Acccount
*/
function mytheme_my_account_orders( $args ) {
// Use -1 to display all orders
$args['posts_per_page'] = 20;
return $args;
}
add_filter( 'woocommerce_my_account_my_orders_query', 'mytheme_my_account_orders', 10, 1 );
@maddisondesigns
maddisondesigns / functions.php
Last active November 30, 2024 04:12
Remove the WooCommerce Marketing Menu
/**
* Remove the WooCommerce Marketing Menu (which also moves the Coupons menu back under the main WooCommerce Menu item)
*/
function mytheme_remove_marketing_menu($features) {
$marketing = array_search('marketing', $features);
unset($features[$marketing]);
return $features;
}
add_filter('woocommerce_admin_features', 'mytheme_remove_marketing_menu' );
@maddisondesigns
maddisondesigns / functions.php
Created November 28, 2024 10:32
Remove the WooCommerce site visibility badge from the Dashboard Admin Bar
/**
* Remove the WooCommerce site visibility badge from the Dashboard Admin Bar
*/
function mytheme_remove_woocommerce_site_visibility_badge( $wp_admin_bar ) {
$wp_admin_bar->remove_node( 'woocommerce-site-visibility-badge' );
}
add_action( 'admin_bar_menu', 'mytheme_remove_woocommerce_site_visibility_badge', 100 );
@maddisondesigns
maddisondesigns / functions.php
Last active November 28, 2024 10:30
Remove the WooCommerce Payments top-level menu item
/**
* In WooCommerce 9.4.1 a new Payments menu item was introduced. For most users, this caused a blank page to be displayed when clicked.
* In WooCommerce 9.4.2 it was fixed so that it no longer shows a blank page, but instead, redirects you to the Payments tab in the WooCommerce Settings.
* When you're not using the WooCommerce Payments Payment Gateway, this menu is completely irrelevant and just adds to the existing clutter
* that WooCommerce already adds into your Dashboard!
*/
function mytheme_remove_payments_menu() {
remove_menu_page( 'admin.php?page=wc-settings&tab=checkout' );
}
add_action( 'admin_init', 'mytheme_remove_payments_menu' );
@maddisondesigns
maddisondesigns / functions.php
Created August 19, 2024 04:48
Remove WordPress PHP Dashboard Widget
/**
* Remove PHP Dashboard Widget
*/
function remove_site_wp_dashboard_widgets() {
remove_meta_box( 'dashboard_php_nag', 'dashboard', 'normal' );
}
add_action( 'wp_dashboard_setup', 'remove_site_wp_dashboard_widgets' );
@maddisondesigns
maddisondesigns / functions.php
Created August 19, 2024 04:47
Remove WordPress Site Health Dashboard Widget
/**
* Remove Site Health Dashboard Widget
*/
function remove_site_wp_dashboard_widgets() {
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
}
add_action( 'wp_dashboard_setup', 'remove_site_wp_dashboard_widgets' );
@maddisondesigns
maddisondesigns / functions.php
Created May 23, 2024 04:31
Perform action/email when a WooCommerce order is placed on-hold
<?php
/**
* Perform action/email when a WooCommerce order is placed on-hold
*/
function wps_woocommerce_order_status_changed( $order_id, $checkout = null ) {
global $woocommerce;
$to = '[email protected]';
$subject = '';
$body = '';
$headers = array('Content-Type: text/html; charset=UTF-8');
@maddisondesigns
maddisondesigns / your-main-plugin-file.php
Last active November 27, 2024 11:53
Declare HPOS compatibility in your WooCommerce plugin. Add this code to your main plugin file.
<?php
/**
* Declare WooCommerce HPOS compatibility
*/
function yourplugin_declare_hpos_compat() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
add_action( 'before_woocommerce_init', 'yourplugin_declare_hpos_compat' );
@maddisondesigns
maddisondesigns / functions.php
Last active September 11, 2023 07:52
Better WordPress is_admin()
<?php
/**
* Check if inside WP Admin. Also works in the Block Editor.
*
* With the introduction of Gutenberg, is_admin() was broken.
* This better version will account for the Block Editor (Gutenberg)
*/
function mytheme_better_is_admin() {
// Check if in Block Editor - see: https://github.com/WordPress/gutenberg/issues/51090#issuecomment-1576570247
if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST && 'edit' === $_GET['context'] ) ) {
@maddisondesigns
maddisondesigns / functions.php
Last active July 28, 2023 03:53
Change the default WordPress login error message to something less specific
/**
* Change the default Login error message
*/
function mytheme_login_error_msg() {
return 'Your username or password is incorrect.';
}
add_filter( 'login_errors', 'mytheme_login_error_msg' );