This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Exit if accessed directly | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
// Check if WP_CLI exists, and only extend it if it does | |
if ( defined( 'WP_CLI' ) && WP_CLI && ! class_exists( 'CP_CLI' ) ) { | |
/** | |
* Class CP_CLI | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Block WordPress xmlrpc.php requests. | |
<Files xmlrpc.php> | |
deny from all | |
</Files> | |
# Block direct access to wp-config.php. | |
<Files wp-config.php> | |
Deny from all | |
</Files> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once(WC()->plugin_path().'/includes/admin/reports/class-wc-admin-report.php'); | |
add_filter( 'woocommerce_admin_reports', 'my_custom_woocommerce_admin_reports', 10, 1 ); | |
function my_custom_woocommerce_admin_reports( $reports ) { | |
$sales_by_country = array( | |
'sales_by_country' => array( | |
'title' => 'Sales By Country', | |
'description' => '', | |
'hide_title' => true, | |
'callback' => 'sales_by_country_callback', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: User Switching Notice for WooCommerce | |
* Plugin URI: https://gist.github.com/bekarice/7785293fb60d7d5297a245b1c1271272 | |
* Description: Adds a frontend notice to switch back to your user on WooCommerce sites with User Switching. | |
* Author: SkyVerge | |
* Author URI: http://www.skyverge.com/ | |
* Version: 1.0.0 | |
* Text Domain: user-switching-notice-for-woocommerce | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_shortcode( 'wc_geo_country_name', 'wcct_custom_get_user_geo_country_name' ); | |
function wcct_custom_get_user_geo_country_name() { | |
$geo = new WC_Geolocation(); // Get WC_Geolocation instance object | |
$user_ip = $geo->get_ip_address(); // Get user IP | |
$user_geo = $geo->geolocate_ip( $user_ip ); // Get geolocated user data. | |
$country = $user_geo['country']; // Get the country code | |
return WC()->countries->countries[ $country ]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Version 1.4 | |
const DAY_IN_SECONDS = 60*60*24; | |
const BLACKLISTED_URL_PARAMS = [ | |
'fbclid', // Google Ads click Id | |
'gclid', // Facebook click Id | |
'msclkid', // Micorosft Ads Click Id | |
]; | |
addEventListener('fetch', event => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // do not copy this line | |
/** | |
* WordPress will automatically create a Mine view for post types that have multiple authors. | |
* With a recent change to WooCommerce core, the customers are now the author of the orders, so Mine is | |
* showing and causing confusion. This filter will remove Mine from orders. | |
* | |
* @param arr $views The current views being used for orders. | |
* @return arr The edited views array. | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Add a WooCommerce order status (completed, refunded) into the Dashboard status widget | |
function woocommerce_add_order_status_dashboard_widget() { | |
if ( ! current_user_can( 'edit_shop_orders' ) ) { | |
return; | |
} | |
$refunded_count = 0; | |
$completed_count = 0; | |
foreach ( wc_get_order_types( 'order-count' ) as $type ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref. https://jeroensormani.com/ultimate-guide-to-woocommerce-checkout-fields/ | |
//This post is meant as a one stop shop if you’d like to make any kind of customizations to your WooCommerce checkout fields. Whether this is adding additional fields, removing some unneeded ones or changing the order they’re displayed in. | |
This post is meant as a one stop shop if you’d like to make any kind of customizations to your WooCommerce checkout fields. Whether this is adding additional fields, removing some unneeded ones or changing the order they’re displayed in. | |
Additionally there will be guides on how do display fields two field side by side, updates the order totals when a field changes and how to add basic field validation. | |
This is a post with a lot of code snippets and likely requires changes for it to fit your exact needs. Prefer to use a plugin instead? Take a look at my Advanced Checkout Fields for WooCommerce plugin. | |
Good to Know | |
These are some good to know files, hooks and functions/methods. Some of these |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // do not copy this line | |
/** | |
* In case you'd like to send an email to the admin when a new customer is created in WooCommerce. | |
* @param int $user_id New user's ID | |
*/ | |
function send_wc_admin_new_user_notification( $user_id ) { | |
wp_send_new_user_notifications( $user_id, 'admin' ); | |
} | |
add_action( 'woocommerce_new_customer', 'send_wc_admin_new_user_notification' ); |