Skip to content

Instantly share code, notes, and snippets.

@bekarice
bekarice / wc-sku-sorting.php
Last active November 30, 2023 22:21
Sort WooCommerce Products by SKU
View wc-sku-sorting.php
<?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-add-order-item-meta-to-rest-response.php
Created December 28, 2016 20:18
Example: Add order item meta to WC REST API
View wc-add-order-item-meta-to-rest-response.php
<?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
View wc-custom-order-action-sample.php
<?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
View registration-order-link-for-woocommerce.php
@bekarice
bekarice / wc-change-return-to-shop-link.php
Last active August 8, 2023 19:30
Change WooCommerce return to shop URL
View wc-change-return-to-shop-link.php
@bekarice
bekarice / wc-memberships-post-types-blacklist.php
Created August 31, 2015 20:10
Dev Docs Example: WooCommerce Memberships Post Types Blacklist
View wc-memberships-post-types-blacklist.php
<?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
View filter-wc-orders-by-gateway.php
<?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
View wc-disable-any-repeat-purchase.php
<?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 ) {
@bekarice
bekarice / wc-prevent-checkout-for-cart-with-specific-category.php
Last active June 29, 2023 20:32
Prevents checkout if the WooCommerce cart only contains items from a specific category
View wc-prevent-checkout-for-cart-with-specific-category.php
<?php // only copy this line if needed
/**
* Renders a notice and prevents checkout if the cart
* only contains products in a specific category
*/
function sv_wc_prevent_checkout_for_category() {
// set the slug of the category for which we disallow checkout
$category = 'clothing';
@bekarice
bekarice / wc-add-shop-loop.php
Last active April 16, 2023 18:06
Add WooCommerce product meta to the shop loop
View wc-add-shop-loop.php
/**
* Will add information to the shop loop above the "Add to cart" button
* This example will use post meta (custom fields) and display them if set
* Tutorial: http://www.skyverge.com/blog/add-information-to-woocommerce-shop-page/
**/
function skyverge_shop_display_post_meta() {
global $product;