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
Last active February 7, 2024 13:42
WooCommerce Custom Fields for Simple & Variable Products
/*
* Add our Custom Fields to simple products
*/
function mytheme_woo_add_custom_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
// Text Field
@maddisondesigns
maddisondesigns / functions.php
Last active February 2, 2024 23:04
Create WordPress Custom Post Types & Taxonomies, and add custom columns to display CPT data
<?php
/**
* Add an action when WP Admin initialises to register our Custom Post Type
*/
function mdsgns_create_custom_post_types() {
$types = array(
// Where the magic happens
array(
'the_type' => 'store',
@maddisondesigns
maddisondesigns / your-main-plugin-file.php
Last active October 25, 2023 08:22
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' );
@maddisondesigns
maddisondesigns / functions.php
Last active April 12, 2023 06:20
Display the name of the current WordPress template being used
<?php
/**
* Debug function to show the name of the current template being used
*/
function mytheme_show_template() {
global $template;
if ( is_user_logged_in() ) {
echo '<div style="background-color:#000;color:#fff;z-index:9999;position:absolute;top:0;">';
print_r( $template );
if ( is_single() ) {
@maddisondesigns
maddisondesigns / functions.php
Last active January 24, 2023 20:44
Hide those annoying Automattic/WooCommerce/Jetpack/WordPress adverts & promos
<?php
/**
* Turn off WooCommerce Marketplace suggestions
*/
add_filter( 'woocommerce_allow_marketplace_suggestions', '__return_false' );
/**
* Turn off WooCommerce Feature Plugin notice
*/
add_filter( 'woocommerce_show_admin_notice', '__return_false', 'wc_admin_feature_plugin_notice' );
@maddisondesigns
maddisondesigns / functions.php
Last active January 4, 2023 17:20
Convert Phone Word to Phone Number
<?php
/**
* Convert a phone number containing words, to a plain number. e.g. '1800 CALLME' == '1800225563'
*/
function ephemeris_phone_word_to_number( $phone_number ) {
$phone_word_pattern = array(
'a' => '2',
'b' => '2',
'c' => '2',
'd' => '3',
@maddisondesigns
maddisondesigns / functions.php
Created August 10, 2022 06:52
Remove the WordPress Site Health Dashboard Widget
/**
* Remove the Site Health Dashboard Widget
*/
function ephemeris_remove_site_health_dashboard_widget() {
remove_meta_box( 'dashboard_site_health', 'dashboard', 'normal' );
}
add_action( 'wp_dashboard_setup', 'ephemeris_remove_site_health_dashboard_widget' );
@maddisondesigns
maddisondesigns / cookie-policy.md
Last active June 19, 2022 17:59
eCommerce Terms & Conditions and Privacy Templates