Skip to content

Instantly share code, notes, and snippets.

View vanbo's full-sized avatar

Ivan Andreev vanbo

View GitHub Profile
@vanbo
vanbo / wc-allow-free-shipping-up-to-max-amount
Last active October 27, 2017 11:12
WooCommerce: Allow Free Shipping up to Certain Amount
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'prefix_is_available_up_to_max_amount', 10, 3 );
/**
* @param bool $is_available
* @param array $package Shipping package.
* @param WC_Shipping_Free_Shipping $shipping_class
* @return bool
*/
function prefix_is_available_up_to_max_amount( $is_available, $package, $shipping_class ) {
$max_amount = 200;
$total = WC()->cart->get_displayed_subtotal();
@vanbo
vanbo / wc-css-make-storefront-product-tabs-horizontal
Created October 27, 2017 11:33
WooCommerce: CSS to make Storefront product tabs horizontal again
.product .woocommerce-tabs ul.tabs {
width: 100%;
float: none;
margin-right: 5.8823529412%;
}
.woocommerce div.product .woocommerce-tabs ul.tabs {
list-style: none;
padding: 0 0 0 1em;
margin: 0 0 1.618em;
@vanbo
vanbo / wc-allow-free-shipping-when-certain-product-in-cart
Created October 27, 2017 12:39
WooCommerce: Allow free shipping when certain product is in cart
add_filter( 'woocommerce_shipping_free_shipping_is_available', 'prefix_is_available_for_certain_products', 10, 3 );
/**
* @param bool $is_available
* @param array $package Shipping package.
* @param WC_Shipping_Free_Shipping $shipping_class
*
* @return bool
*/
function prefix_is_available_for_certain_products( $is_available, $package, $shipping_class ) {
@vanbo
vanbo / wc-multiple-recipients-to-processing-order-email
Created October 30, 2017 11:13
WooCommerce: Multiple recipients to "Processing Order" email
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'prefix_add_recipients_to_processing_order_email', 10, 2 );
/**
* @param string $recipient The recipient email, usually the billing address email
* @param WC_Order $order
*
* @return string
*/
function prefix_add_recipients_to_processing_order_email( $recipient, $order ) {
// Add as many emails to the recipient as you want by separating them with ","
@vanbo
vanbo / wc-hide-core-notice
Last active October 30, 2017 20:37
WooCommerce: Hide Core notice
add_filter( 'woocommerce_show_admin_notice', 'prefix_show_updated_notice', 10, 2 );
function prefix_show_updated_notice( $show, $notice ) {
// Check for the notice you want to hide
// Refer to the WC_Admin_Notices::$code_notices (array keys) for the values
// Update notice?
if ( 'update' != $notice ) {
return $show;
}
@vanbo
vanbo / wc-block-admin-from-login-form
Created October 30, 2017 20:32
WooCommerce: Block admistrator from WC Login form
add_filter( 'woocommerce_login_credentials', 'prefix_check_admin_login' );
function prefix_check_admin_login( $credentials ) {
if ( is_email( $credentials['user_login'] ) ) {
$user = get_user_by( 'email', $credentials['user_login'] );
} else {
$user = get_user_by( 'login', $credentials['user_login'] );
}
// If the user is administrator or has any rights that you want
if ( user_can( $user, 'administrator' ) ) {
@vanbo
vanbo / wc-filter-product-shipping-weight
Created November 2, 2017 15:52
WooCommerce: Filter a product shipping weight
// Filters both variations and simple products with the same function
add_filter( 'woocommerce_product_variation_get_weight', 'filter_product_weight', 10, 2 );
add_filter( 'woocommerce_product_get_weight', 'filter_product_weight', 10, 2 );
/**
* @param float $weight
* @param WC_Product $product
*
* @return int
*/
function filter_product_weight( $weight, $product ) {
@vanbo
vanbo / wc-paytrace-add-parameters-to-transaction
Created December 21, 2017 10:11
WC Paytrace, Add parameters to transaction request
add_filter( 'wc_paytrace_transaction_request', 'prefix_filter_paytrace_transaction_request', 10, 5 );
/**
* @param array $request_parameters
* @param WC_Order $order The order to be charged
* @param float $amount Amount to be charged
* @param bool $is_subscription Is this a subscription
* @param bool $is_paid_with_profile Is this a profile payment(true) or new card is used(false)
*
* @return array
*/
@vanbo
vanbo / wc-paytrace-request-discretionary-data-field
Last active May 16, 2019 14:21
WooCommerce Paytrace - Add Discretionary data field to the request
add_filter( 'wc_paytrace_transaction_request', 'prefix_filter_paytrace_transaction_request', 10, 5 );
/**
* @param array $request_parameters
* @param WC_Order $order The order to be charged
* @param float $amount Amount to be charged
* @param bool $is_subscription Is this a subscription
* @param bool $is_paid_with_profile Is this a profile payment(true) or new card is used(false)
*
* @return array
*/
@vanbo
vanbo / wc-change-complete-order-status
Created February 5, 2018 11:01
WC: Change complete order status
add_filter( 'woocommerce_payment_complete_order_status', 'prefix_filter_wc_complete_order_status', 10, 3 );
/**
* @param string $status
* @param int $order_id
* @param WC_Order $order
*
* @return string
*/
function prefix_filter_wc_complete_order_status( $status, $order_id, $order ) {
return 'on-hold';