Skip to content

Instantly share code, notes, and snippets.

@bekarice
bekarice / wc-sku-sorting.php
Last active April 8, 2024 17:56
Sort WooCommerce Products by SKU
<?php // ONLY COPY THIS LINE IF NEEDED!
/**
* Adds the ability to sort products in the shop based on the SKU
* Can be combined with tips here to display the SKU on the shop page: https://www.skyverge.com/blog/add-information-to-woocommerce-shop-page/
*
* @param array $args the sorting args
* @return array updated args
*/
function sv_add_sku_sorting( $args ) {
@bekarice
bekarice / wc-memberships-role-changes-handler.php
Created October 5, 2015 01:45
WooCommerce Memberships: Trigger role changes for active <-> inactive membership status changes
<?php
/**
* Replaces the Site Member role with the Customer role when a membership becomes inactive
*
* @param \WC_User_Membership $user_membership the user's membership
* @param string $old_status the previous membership status
* @param string $new_status the new membership status
*/
function sv_update_user_role_with_membership( $user_membership, $old_status, $new_status ) {
@bekarice
bekarice / wc-active-shipping-methods-widget.php
Last active January 25, 2024 23:08
WooCommerce Active Shipping Methods Widget
<?php
/**
* Plugin Name: WooCommerce Active Shipping Widget
* Plugin URI: https://www.skyverge.com/blog/how-to-create-a-woocommerce-widget/
* Description: Adds a widget to display a list of active WooCommerce shipping methods
* Author: SkyVerge
* Author URI: https://www.skyverge.com/
* Version: 1.0.0
* Text Domain: wc-active-shipping-widget
*
@bekarice
bekarice / wc-add-order-item-meta-to-rest-response.php
Created December 28, 2016 20:18
Example: Add order item meta to WC REST API
<?php // only copy if needed
/**
* Example: Add order meta to the REST API
* WC 2.6+
*
* @param \WP_REST_Response $response The response object.
* @param \WP_Post $post Post object.
* @param \WP_REST_Request $request Request object.
* @return object updated response object
@bekarice
bekarice / wc-custom-order-action-sample.php
Created October 24, 2016 06:55
Add a WooCommerce custom order action
<?php // only copy if needed
/**
* Add a custom action to order actions select box on edit order page
* Only added for paid orders that haven't fired this action yet
*
* @param array $actions order actions array to display
* @return array - updated actions
*/
function sv_wc_add_order_meta_box_action( $actions ) {
@bekarice
bekarice / registration-order-link-for-woocommerce.php
Last active August 16, 2023 06:13
Automatically link previous orders to new WooCommerce customer accounts upon registration
@bekarice
bekarice / wc-change-return-to-shop-link.php
Last active August 8, 2023 19:30
Change WooCommerce return to shop URL
@bekarice
bekarice / wc-memberships-post-types-blacklist.php
Created August 31, 2015 20:10
Dev Docs Example: WooCommerce Memberships Post Types Blacklist
<?php
// Remove Sensei Messages from post types that can be restricted by a plan
function sv_add_post_type_memberships_blacklist( $blacklist ) {
$blacklist[] = 'sensei_message';
return $blacklist;
}
add_filter( 'wc_memberships_content_restriction_excluded_post_types', 'sv_add_post_type_memberships_blacklist' );
@bekarice
bekarice / filter-wc-orders-by-gateway.php
Last active August 3, 2023 13:37
Filters WooCommerce Orders by Payment Gateway Used
<?php
/**
* Plugin Name: Filter WooCommerce Orders by Payment Method
* Plugin URI: http://skyverge.com/
* Description: Filters WooCommerce orders by the payment method used :)
* Author: SkyVerge
* Author URI: http://www.skyverge.com/
* Version: 1.0.0
* Text Domain: wc-filter-orders-by-payment
*
@bekarice
bekarice / wc-disable-any-repeat-purchase.php
Last active July 26, 2023 12:19
Disables Repeat Purchase for any WooCommerce product
<?php
/**
* Disables repeat purchase for products / variations
*
* @param bool $purchasable true if product can be purchased
* @param \WC_Product $product the WooCommerce product
* @return bool $purchasable the updated is_purchasable check
*/
function sv_disable_repeat_purchase( $purchasable, $product ) {