Skip to content

Instantly share code, notes, and snippets.

@shreyans94
shreyans94 / gist:065bfdf21ebff9556356d0d944a80318
Created August 1, 2017 08:03
Sort out of stock in category & Shop pages for Woocommerce
// Add custom Theme Functions here
/**
* Sorting out of stock WooCommerce products - Order product collections by stock status, in-stock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
// Check if WooCommerce is active
@shreyans94
shreyans94 / gist:500e105a441279ac0cd945ad93ab7c3b
Last active January 29, 2018 14:16
Product Variation Custom Fields
add_filter( 'woocommerce_available_variation', 'load_variation_settings_fields' );
function load_variation_settings_fields($variations) {
// duplicate the line for each field
/*$variations['veg_nonveg'] = get_post_meta( $variations[ 'variation_id' ], '_veg-nonveg');
$variations['no_serving'] = get_post_meta( $variations[ 'variation_id' ], '_no-serving', true );
$variations['serving_size'] = get_post_meta( $variations[ 'variation_id' ], '_serving-size', true );
$variations['total_protein'] = get_post_meta( $variations[ 'variation_id' ], '_total-protein', true );
$variations['protein_percentage'] = get_post_meta( $variations[ 'variation_id' ], '_protein-percentage', true );
$variations['protein_per_serving'] = get_post_meta( $variations[ 'variation_id' ], '_protein-per-serving', true );
@shreyans94
shreyans94 / gist:f8d11af839dfc2e11b1d6a281077028a
Created January 23, 2018 21:32
Change woocommerce price format from range to "From:"
/**
* Change price format from range to "From:"
*
* @param float $price
* @param obj $product
* @return str
*/
function iconic_variable_price_format( $price, $product ) {
$prefix = sprintf('%s: ', __('From', 'iconic'));
@shreyans94
shreyans94 / gist:05b10194cf2f57cf054a5cf3da3fd931
Created January 23, 2018 21:32
Display ACF for woocommerce variations in backend
// Render fields at the bottom of variations - does not account for field group order or placement.
add_action( 'woocommerce_product_after_variable_attributes', function( $loop, $variation_data, $variation ) {
global $abcdefgh_i; // Custom global variable to monitor index
$abcdefgh_i = $loop;
// Add filter to update field name
add_filter( 'acf/prepare_field', 'acf_prepare_field_update_field_name' );
// Loop through all field groups
$acf_field_groups = acf_get_field_groups();
foreach( $acf_field_groups as $acf_field_group ) {
@shreyans94
shreyans94 / gist:c2b99d03b2c57696fb4627f2b0a8c3ca
Created January 23, 2018 21:34
Coupon Restriction option in WooCommerce Smart COD Plugin
add_filter( 'wc_smart_cod_available', 'cod_restrict_coupons' );
function cod_restrict_coupons( $is_cod_available ) {
global $woocommerce;
$applied_coupons = $woocommerce->cart->applied_coupons;
// add the coupon codes you want
// to restrict in this array
$restricted_coupons = array(
/* Yith Add 'Submit review' Link on Top */
if( defined('YITH_YWAR_PREMIUM') ){
add_action( 'ywar_summary_prepend','yith_ywar_show_submit_review_link',5 );
function yith_ywar_show_submit_review_link(){
echo '<a href="#review_form_wrapper">Submit review</a>';
}
}
@shreyans94
shreyans94 / gist:1855adf0b7983e24cf25be5cb4e76886
Created January 23, 2018 21:35
Apply woocommerce product title to all product images alt tags (WooThumbs Compatible)
function iconic_modify_woothumbs_all_images_data( $image_data, $product_id ) {
$title = get_the_title( $product_id );
foreach( $image_data as $index => $image ) {
$image_data[ $index ]['alt'] = $title;
}
return $image_data;
}
@shreyans94
shreyans94 / gist:2c5c927573f6f16a41298e684ff6013d
Created January 23, 2018 21:36
Allow editing of woocommerce orders under status of Processing
add_filter( 'wc_order_is_editable', 'wc_make_processing_orders_editable', 10, 2 );
function wc_make_processing_orders_editable( $is_editable, $order ) {
if ( $order->get_status() == 'processing' ) {
$is_editable = true;
}
return $is_editable;
}
@shreyans94
shreyans94 / Remove woocommerce print invoice and packing slip plugin invoice link from emails.txt
Last active January 29, 2018 14:16
Remove woocommerce print invoice and packing slip plugin invoice link from emails
@shreyans94
shreyans94 / gist:0a2a2f96968dc65ba43aa9647c4e7d5f
Created January 23, 2018 21:37
Add scroll feature in Guaven Woo Search Box Plugin
function custom_guaven_js(){
?>
<script>
jQuery(window).scroll(function(){
var guaven_woos_offset = jQuery('.header-search-form-wrapper [name="s"]').offset();
jQuery(".guaven_woos_suggestion").css('left', guaven_woos_offset.left);
jQuery(".guaven_woos_suggestion").css('top', guaven_woos_offset.top + parseFloat(jQuery('.header-search-form-wrapper [name="s"]').outerHeight()));
});
</script>
<?php