Skip to content

Instantly share code, notes, and snippets.

View mitchellkrogza's full-sized avatar
🤓
Busy ... Always busy

Mitchell Krog mitchellkrogza

🤓
Busy ... Always busy
View GitHub Profile
@mitchellkrogza
mitchellkrogza / inline-flatsome.css
Last active June 23, 2021 06:57
Inline flatsome.css (Flatsome Theme)
// This function can be adapted and modified to inline any theme or plugin CSS you like
// Inlining any critical CSS can make big improvements on your site speed
// Dont get carried away inlining everything - Keep it to critical and essential CSS
add_action('wp_head', 'inject_flatsome', 5);
function inject_flatsome() {
ob_start();
include 'wp-content/themes/flatsome/assets/css/flatsome.css';
$atf_css = ob_get_clean();
if ($atf_css != "" ) {
echo '<style id="inline-css" type="text/css">'. $atf_css . '</style>';
@mitchellkrogza
mitchellkrogza / woo-increase-variations
Last active June 22, 2021 12:44
Woocommerce Increase Variations per Page (Admin)
// NOTE: Setting this too high (even 50) can cause freezing when saving variations
// A 400 Bad Request can be registered on wpadmin-ajax.php when too high
add_filter( 'woocommerce_admin_meta_boxes_variations_per_page', 'woo_increase_variations_per_page' );
function woo_increase_variations_per_page() {
return 50;
}
<?php
global $product;
$attachment_ids = $product->get_gallery_attachment_ids();
foreach( $attachment_ids as $attachment_id )
{
//Get URL of Gallery Images - default wordpress image sizes
echo $Original_image_url = wp_get_attachment_url( $attachment_id );
echo $full_url = wp_get_attachment_image_src( $attachment_id, 'full' )[0];
echo $medium_url = wp_get_attachment_image_src( $attachment_id, 'medium' )[0];
@mitchellkrogza
mitchellkrogza / woocommerce-backorder-text
Created June 14, 2021 05:51
Change Woocommerce backorder message text
// Change backorder message text
function change_backorder_message( $text, $product ){
    if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
        $text = __( 'Place your text here', 'woocommerce' );
    }
    return $text;
}
add_filter( 'woocommerce_get_availability_text', 'change_backorder_message', 10, 2 );
@mitchellkrogza
mitchellkrogza / WCAdminLastOrderNote
Created June 9, 2021 14:59 — forked from bjornpatje/WCAdminLastOrderNote.php
Add note to Admin mail with latest customer order ID
add_action( 'woocommerce_email_order_details', 'las_order_email_order_details', 10, 4 );
function las_order_email_order_details( $order, $sent_to_admin, $plain_text, $email ) {
if($sent_to_admin){
$order_statuses = array('wc-on-hold', 'wc-processing', 'wc-completed');
$customer_user_id = get_current_user_id();
$customer_orders = wc_get_orders( array(
'meta_key' => '_customer_user',
'meta_value' => $customer_user_id,
'post_status' => $order_statuses,
'numberposts' => -1
@mitchellkrogza
mitchellkrogza / disable-woocommerce-blocks-styles-frontend
Created June 9, 2021 14:10
Disable Woocommerce Blocks Stylesheet
/**
* Disable WooCommerce block styles (front-end).
*/
function slug_disable_woocommerce_block_styles() {
wp_dequeue_style( 'wc-block-style' );
}
add_action( 'wp_enqueue_scripts', 'slug_disable_woocommerce_block_styles' );
@mitchellkrogza
mitchellkrogza / woo-change-add-to-cart-button-text
Created June 6, 2021 14:09
Woocommerce Change Add to Cart Button Text
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
}
@mitchellkrogza
mitchellkrogza / css-versioning
Created June 7, 2021 11:00
Add Version Number to theme CSS file
// Version CSS file in a theme
// Uses a Unix Timestring to Version your CSS Files
wp_enqueue_style(
'theme-styles',
get_stylesheet_directory_uri() . '/style.css',
array(),
filemtime( get_stylesheet_directory() . '/style.css' )
);
@mitchellkrogza
mitchellkrogza / fix-woocommerce-max-variations-frontend
Created June 7, 2021 10:58
Fix WooCommerce Limit on Variations (Front End)
/**
* Fix for issue where too many variations causes the front end to not pre-load
* all variations and rely on AJAX.
*/
function custom_wc_ajax_variation_threshold( $qty, $product )
{
return 400;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );
@mitchellkrogza
mitchellkrogza / woocommerce-add-product-brand
Created June 7, 2021 10:56
Add Product Brand to All Products (WooCommerce)
// Add Brand for Products.
// Only use if you sell one brand of item ie. Your own brand
add_filter( 'rank_math/snippet/rich_snippet_product_entity', function( $entity ) {
$entity['brand'] = 'My Brand' ;
return $entity;
});