Skip to content

Instantly share code, notes, and snippets.

View Garconis's full-sized avatar
🐞
Debugging

Jon Fuller Garconis

🐞
Debugging
View GitHub Profile
@Garconis
Garconis / woocommerce-order-email-message-for-categories.php
Created March 20, 2018 21:05
WooCommerce | Add a message to the Order Complete email based on if a product is in certain categories
<?php
add_action( 'woocommerce_email_before_order_table', 'add_content', 20, 4 );
function add_content($order, $sent_to_admin, $plain_text, $email) {
// Adds to "completed order" email only
if ( $email->id == 'customer_completed_order' ) {
// set initial variables to false
$both = false;
@Garconis
Garconis / wp-all-import-today-date-in-filename.php
Created March 23, 2018 15:58
WordPress | Help WP All Import pull in a file if it has today's date in the filename
<?php
// create a function that returns the path of the product import CSV with today's date at the end of the filename
function fs_import_gen_url() {
return "https://www.example.com/csv/your-product-import-" . date("Y_m_d") . ".csv";
// e.g., YYYY_MM_DD = 2019_03_23
}
// then add this shortcode as the URL for the WP All Import file: [fs_import_gen_url()]
@Garconis
Garconis / wp-all-import-send-email-after-import.php
Created March 23, 2018 16:02
WordPress | Have WP All Import send an email when an import is finished
<?php
// Send an email containing the import results after the import has finished
function fs_email_results( $import_id ) {
global $wpdb;
$table = $wpdb->prefix . 'pmxi_imports';
$data = $wpdb->get_row( 'SELECT * FROM `' . $table . '` WHERE `ID` = "' . $import_id . '"' );
if ( $data ) {
$msg = "Import Report for Import ID " . $import_id . "\r\n\r\n";
$msg .= "Created: " . $data->created . "\r\n";
$msg .= "Updated: " . $data->updated . "\r\n";
@Garconis
Garconis / find-numbers-before-percentage.php
Created March 27, 2018 18:54
Find number characters before a percent symbol and display them
<?php
$string = "Take 50.5% OFF";
if (preg_match("/[\d.]+(?=%)/", $string, $matches)) {
$percentage = $matches[0];
echo $percentage;
}
?>
@Garconis
Garconis / wordpress-custom-new-user-email.php
Created March 29, 2018 17:48
WordPress | Custom email for users upon registration
<?php
// https://developer.wordpress.org/reference/hooks/wp_new_user_notification_email/
add_filter( 'wp_new_user_notification_email', 'custom_wp_new_user_notification_email', 10, 3 );
function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
$wp_new_user_notification_email['subject'] = sprintf( 'Acme Co Web Portal Log In', $blogname, $user->user_login );
$message = __( 'You are receiving this email and log in information because you have active project/projects with Acme Co. If you would like, you can check the status of your project/projects by logging into the client portal and clicking on "My Projects". After you log in, "My Projects" is on the left hand side just below the "Dashboard" button.' ) . "\r\n\r\n";
$message .= __( 'Also available in the client portal is the following:' ) . "\r\n\r\n";
$message .= __( 'You can upload files to a team leader' ) . "\r\n";
@Garconis
Garconis / woocommerce-acf-field-output-based-on-attribute-term.php
Last active March 30, 2018 17:29
WooCommerce | Shortcode to output text of a custom ACF options field, based on if a particular product attribute has a certain term
<?php
// Check if product is set to New = Yes and/or Featured = Yes
// then, display the Featured or New product attribute terms if = Yes
add_shortcode( 'fs-product-featured-new', 'fs_product_featured_new_shortcode' );
function fs_product_featured_new_shortcode( $atts ) {
// begin output buffering
ob_start();
// grab the terms of the product's attributes
$new_terms = get_the_terms($post->ID, 'pa_new');
@Garconis
Garconis / woocommerce-product-pricing-table.php
Last active April 3, 2018 13:10
WooCommerce | Product pricing table for simple and variable products
<?php
// Creates a block/card for each product (including variations) with Price, Stock, Size, etc. under each single product display
// https://stackoverflow.com/a/49565625/1887218
// Utility funtion: getting and formtting product data
function format_product_data_output( $the_id ){
$empty = __( '<em>(empty)</em>', 'woocommerce' );
// Get an instance of the WC_Product_Variation object
@Garconis
Garconis / wordpress-wpmu-smush-for-non-admin.php
Created April 19, 2018 20:25
WordPress | WPMU Smush resize only for non-admin users
<?php
// resize only for non-admin
add_filter( 'wp_smush_resize_uploaded_image', 'smush_resize_non_admin', 10, 3 );
function smush_resize_non_admin($should_resize, $id, $meta) {
global $current_user;
if ( current_user_can('manage_options') ) {
return false;
}
@Garconis
Garconis / woocommerce-change-category-page-title.php
Created April 27, 2018 20:51
WooCommerce | Change category page title on the frontend
<?php
/**
* Change "Featured" category name on the frontend
* if on the product page of Featured, then change the "Featured" text to be custom text instead
**/
function change_woocommerce_category_page_title( $page_title ) {
if ( ( is_product_category() ) && ( 'Featured' == $page_title ) ) {
$page_title = "Your Custom Category Title Here";
}
return $page_title;
@Garconis
Garconis / woocommerce-custom-order-email-note-for-product.php
Last active May 30, 2024 19:42
WooCommerce | Add custom text to the emails based on the status of the order and if a product ID is in the order
<?php
/**************
DIFFERENT MESSAGES FOR DIFFERENT PRODUCTS
****************/
//hook our function to the new order email
add_action('woocommerce_email_order_details', 'email_order_details_products', 1, 4);
function email_order_details_products($order, $admin, $plain, $email) {