Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
Busy ... Always busy

Mitchell Krog mitchellkrogza

🤓
Busy ... Always busy
View GitHub Profile
View gist:3227f1b3dc2cb0abc2b6fa0bbb8b600c
<?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 Jun 14, 2021
Change Woocommerce backorder message text
View woocommerce-backorder-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 Jun 9, 2021 — forked from HookCity/WCAdminLastOrderNote
Add note to Admin mail with latest customer order ID
View WCAdminLastOrderNote
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
View disable-woocommerce-blocks-styles-frontend
/**
* 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 Jun 6, 2021
Woocommerce Change Add to Cart Button Text
View woo-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 Jun 7, 2021
Add Version Number to theme CSS file
View css-versioning
// 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 Jun 7, 2021
Fix WooCommerce Limit on Variations (Front End)
View fix-woocommerce-max-variations-frontend
/**
* 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 Jun 7, 2021
Add Product Brand to All Products (WooCommerce)
View woocommerce-add-product-brand
// 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;
});
@mitchellkrogza
mitchellkrogza / woocommerce-ninja-product-enquiry-form
Created Jun 7, 2021
Replace Woocommerce Product Enquiry Form with Ninja Form
View woocommerce-ninja-product-enquiry-form
// Include a Ninja Forms form in a product page. Different forms for simple and variable products.
add_filter( 'the_content', 'ninja_product_enquiry_form' );
function ninja_product_enquiry_form( $content ) {
if ( class_exists( 'woocommerce' ) && is_product() && is_main_query() ) {
global $product;
if ( 'simple' == $product->get_type() ) {
ob_start();
Ninja_Forms()->display( 3 ); // Equivalent to shortcode: [ninja_form id=3]
return $content . ob_get_clean();
}
@mitchellkrogza
mitchellkrogza / woo-notify-cancellation
Created Jun 6, 2021
WooCommerce - Notify Customer of Order Cancellation
View woo-notify-cancellation
function wc_cancelled_order_add_customer_email( $recipient, $order ){
return $recipient . ',' . $order->billing_email;
}
add_filter( 'woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2 );