Skip to content

Instantly share code, notes, and snippets.

View barbareshet's full-sized avatar
🎯
Focusing

ido barnea barbareshet

🎯
Focusing
View GitHub Profile
@woogists
woogists / wc-only-show-free-shipping.php
Last active October 3, 2020 19:08
[General Snippets][Hide other shipping methods when “Free Shipping” is available]
/**
* woocommerce_package_rates is a 2.1+ hook
*/
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
/**
* Hide shipping rates when free shipping is available
*
* @param array $rates Array of rates found for the package
* @param array $package The package array/object being shipped
@woogists
woogists / wc-adjust-quantity-input.php
Last active December 6, 2021 10:39
Adjust the quantity input values
/**
* Adjust the quantity input values
*/
add_filter( 'woocommerce_quantity_input_args', 'jk_woocommerce_quantity_input_args', 10, 2 ); // Simple products
function jk_woocommerce_quantity_input_args( $args, $product ) {
if ( is_singular( 'product' ) ) {
$args['input_value'] = 2; // Starting value (we only want to affect product pages, not cart)
}
$args['max_value'] = 80; // Maximum value
@woogists
woogists / wc-disable-specific-stylesheets.php
Last active October 8, 2024 22:19
[Theming Snippets] Disable specific stylesheets
/**
* Set WooCommerce image dimensions upon theme activation
*/
// Remove each style one by one
add_filter( 'woocommerce_enqueue_styles', 'jk_dequeue_styles' );
function jk_dequeue_styles( $enqueue_styles ) {
unset( $enqueue_styles['woocommerce-general'] ); // Remove the gloss
unset( $enqueue_styles['woocommerce-layout'] ); // Remove the layout
unset( $enqueue_styles['woocommerce-smallscreen'] ); // Remove the smallscreen optimisation
return $enqueue_styles;
@woogists
woogists / wc-add-custom-field.php
Last active September 23, 2021 20:53
Add a custom field (in an order) to the emails
/**
* Add a custom field (in an order) to the emails
*/
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['meta_key'] = array(
'label' => __( 'Label' ),
'value' => get_post_meta( $order->id, 'meta_key', true ),
);
@woogists
woogists / wc-send-coupons-by-email.php
Last active January 25, 2024 20:15
Send coupons used in an order by email
/**
* Send an email each time an order with coupon(s) is completed
* The email contains coupon(s) used during checkout process
*
*/
function woo_email_order_coupons( $order_id ) {
$order = new WC_Order( $order_id );
if( $order->get_used_coupons() ) {
@woogists
woogists / wc-min-order-amount.php
Last active November 18, 2022 22:30
Set a minimum order amount for checkout
/**
* Set a minimum order amount for checkout
*/
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {
// Set this variable to specify a minimum order value
$minimum = 50;
@ahmadawais
ahmadawais / mixin.scss
Last active January 25, 2023 09:09
Sass SCSS Responsive Media Queries Mixin for Eight Different Screen Sizes
/**
* MIXIN: Responsive Media Queries.
*
* Creates responsive media queries for eight different screen sizes.
* These are based on min-width which means if x is the size then your
* CSS will affect any device with screen width x and above.
*
* USAGE:
* @include r(240) { }
* @include r(320) { }
@sirbrillig
sirbrillig / functions.php
Last active November 20, 2024 09:52 — forked from UmeshSingla/functions.php
Post file using wp_remote_post in WordPress
<?php
$local_file = 'file_path'; //path to a local file on your server
$post_fields = array(
'name' => 'value',
);
$boundary = wp_generate_password( 24 );
$headers = array(
'content-type' => 'multipart/form-data; boundary=' . $boundary,
);
anonymous
anonymous / untitled36_.idea_.name
Created May 2, 2017 22:09
jewishstore
untitled36
@ajskelton
ajskelton / WP Customizer - Select
Last active May 14, 2024 04:54
Add a Select field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_select_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_select',
'default' => 'value1',
) );
$wp_customize->add_control( 'themeslug_select_setting_id', array(
'type' => 'select',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Select Option' ),