Skip to content

Instantly share code, notes, and snippets.

Avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / phpcs.xml
Created June 28, 2023 13:48
PHP_CodeSniffer ruleset for marketplace products
View phpcs.xml
<?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.
View wc-core-in-stock-quanity-not-tracked.php
<?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
View wc-brands-add-to-product-loop.php
<?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
View wc-shortcode-top-level-product-category-list.php
<?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
View woocommerce-subscriptions-download-access-after-cancelled.php
<?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)
View woocommerce-subscriptions-preserve-billing-schedule.php
<?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' );
@woogists
woogists / wc-subscriptions-enable-emails-on-staging.php
Created November 4, 2022 16:57
[WooCommerce Subscriptions] Enabling Subscriptions Emails on a Staging Site
View wc-subscriptions-enable-emails-on-staging.php
// Enable subscription-related emails on a staging site
if ( ! defined( 'WCS_FORCE_EMAIL' ) ) {
define( 'WCS_FORCE_EMAIL', true );
}
@woogists
woogists / wc-core-change-default-cart-session.php
Last active July 14, 2022 12:01
[WooCommerce Core] Change default cart session length
View wc-core-change-default-cart-session.php
<?php
// Sets when the session is about to expire
add_filter( 'wc_session_expiring', 'woocommerce_cart_session_about_to_expire');
function woocommerce_cart_session_about_to_expire() {
// Default value is 47
return 60 * 60 * 47;
}
@woogists
woogists / wc-product-vendors-change-url-slug.php
Last active July 29, 2022 00:09
[Product Vendors] Change the vendor URL slug
View wc-product-vendors-change-url-slug.php
add_filter( 'wcpv_vendor_slug', 'change_product_vendors_slug' );
function change_product_vendors_slug() {
return 'your-new-slug';
}
@woogists
woogists / wc-brands-breadcrumbs-into-links.php
Created July 6, 2022 06:34
[Brands] Turn Brand Breadcrumbs into links
View wc-brands-breadcrumbs-into-links.php