Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / wc-core-adjust-non-base-location-prices.php
Last active March 25, 2024 19:36
Customers everywhere pay the same price and the difference in taxes is absorbed by adjusting the product price relative to the tax.
<?php
add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false' );
@woogists
woogists / wc-core-show-empty-taxes.php
Last active March 25, 2024 19:37
Show empty taxes
<?php
add_filter( 'woocommerce_order_hide_zero_taxes', '__return_false' );
@woogists
woogists / wc-core-apply-tax-based-on-subtotal.php
Last active July 5, 2024 16:51
Apply WooCommerce tax based on the subtotal
<?php
add_filter( 'woocommerce_product_get_tax_class', 'big_apple_get_tax_class', 1, 2 );
function big_apple_get_tax_class( $tax_class, $product ) {
if ( WC()->cart->subtotal <= 110 )
$tax_class = 'Zero Rate';
return $tax_class;
}
@woogists
woogists / wc-product-addons-sold-individually.php
Created December 29, 2023 11:52
[Product Add-ons] Allow one instance of Sold Individually products in the cart, even if they have different add-ons selected
<?php
add_filter( 'woocommerce_add_to_cart_validation', 'check_if_product_exists_in_cart', 10, 2 );
function check_if_product_exists_in_cart( $is_valid, $product_id ) {
$product = wc_get_product( $product_id );
if ( $product->is_sold_individually() ) {
@woogists
woogists / phpcs.xml
Last active October 31, 2024 22:49
PHP_CodeSniffer ruleset for marketplace products
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<description>WooCommerce extension PHP_CodeSniffer ruleset.</description>
<!-- Exclude paths -->
<exclude-pattern>tests/</exclude-pattern>
<exclude-pattern>woo-includes/woo-functions.php</exclude-pattern>
<exclude-pattern>woo-includes/class-wc-dependencies.php</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
@woogists
woogists / wc-core-in-stock-quanity-not-tracked.php
Created June 21, 2023 12:40
Display that a product is in stock even if Track Stock Quantity is not enabled under the product's Inventory tab.
<?php
add_filter( 'woocommerce_get_availability', 'custom_override_woocommerce_show_in_stock', 10, 2 );
function custom_override_woocommerce_show_in_stock( $availability, $product ) {
if ( ! $product->managing_stock() && $product->is_in_stock() ) {
$availability['availability'] = __( 'In Stock', 'woocommerce' );
}
@woogists
woogists / wc-brands-add-to-product-loop.php
Last active June 2, 2023 14:25
[WooCommerce Brands] Add Brands to Product Loop
<?php
if ( is_plugin_active( 'woocommerce-brands/woocommerce-brands.php' ) ) {
add_action( 'woocommerce_shop_loop_item_title', 'add_brands_to_product_loop' );
// Add brands to product loop.
function add_brands_to_product_loop() {
$terms = get_the_terms( get_the_ID(), 'product_brand' );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$term = join( ', ', wp_list_pluck( $terms, 'name' ) );
@woogists
woogists / wc-shortcode-top-level-product-category-list.php
Created April 13, 2023 10:42
Top-level Product Category List Shortcode
<?php
/*
* The shortcode is [top_level_product_categories_list]
*/
add_shortcode('top_level_product_categories_list', 'wc_shortcode_top_level_product_categories_list');
function wc_shortcode_top_level_product_categories_list() {
ob_start();
@woogists
woogists / woocommerce-subscriptions-download-access-after-cancelled.php
Last active June 28, 2023 02:45
[WooCommerce Subscriptions]: Give access to downloadable files even if Subscription is cancelled
<?php
/*
* Access to downloadable files associated with a subscription will, by default, expire
* when the subscription is no longer "active" or "pending-cancel".
* https://woocommerce.com/document/subscriptions/faq/#section-39
* This snippet overrides that behavior to allow access as per the Download Expiry settng
* when the subscription status is "cancelled"
*/
@woogists
woogists / woocommerce-subscriptions-preserve-billing-schedule.php
Created March 7, 2023 14:38
WooCommerce Subscriptions (Preserve Billing Schedule)
<?php
/*
* By default, WooCommerce Subscriptions will calculate the next payment date for a subscription from the time of the last payment.
* This snippet changes it to calculate the next payment date from the scheduled payment date, not the time the payment was actually processed.
*/
add_filter( 'wcs_calculate_next_payment_from_last_payment', '__return_false' );