Skip to content

Instantly share code, notes, and snippets.

Avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / wc-subscriptions-enable-emails-on-staging.php
Created Nov 4, 2022
[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 Jul 14, 2022
[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 Jul 29, 2022
[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 Jul 6, 2022
[Brands] Turn Brand Breadcrumbs into links
View wc-brands-breadcrumbs-into-links.php
View wc-360-image-playspeed.php
add_filter( 'wc360_js_playspeed', 'adjust_play_speed_for_wc360' );
function adjust_play_speed_for_wc360( $speed ) {
return 750;
}
@woogists
woogists / gist:e67d8e6c9d3bbf48dc266b8082798bda
Created Apr 29, 2022
[Conditional Shipping & Payments] Creating new conditions that include multiple modifiers
View gist:e67d8e6c9d3bbf48dc266b8082798bda
<?php
add_filter( 'woocommerce_csp_conditions', function( $condition_classes ) {
class WC_CSP_Condition_Package_Item_Quantity_Bottles extends WC_CSP_Condition_Package_Item_Quantity {
public function __construct() {
parent::__construct();
$this->id = 'bottles_in_package';
$this->title = __( 'Bottles Count', 'woocommerce-conditional-shipping-and-payments' );
}
@woogists
woogists / woo-blocks-check-house-number-in-billing-and-shipping-address.php
Created Apr 20, 2022
[WooCommerce Blocks] Check if the billing and shipping address contains a house number
View woo-blocks-check-house-number-in-billing-and-shipping-address.php
<?php
add_action( 'woocommerce_store_api_checkout_update_order_from_request', 'woo_blocks_address_field_validation', 10, 2);
function woo_blocks_address_field_validation( WC_Order $order, $request ) {
$shipping_address = $order->get_address('shipping')['address_1'];
$billing_address = $order->get_address('billing')['address_1'];
if ( $shipping_address && ! preg_match( '/[0-9]+/', $shipping_address ) ) {
throw new Exception( 'Your shipping address must contain a house number!' );
}
@woogists
woogists / woo-blocks-check-house-number-in-billing-address.php
Last active Apr 20, 2022
[WooCommerce Blocks] Check if the billing address contains a house number
View woo-blocks-check-house-number-in-billing-address.php
<?php
add_action( 'woocommerce_store_api_checkout_update_order_from_request', 'woo_blocks_address_field_validation', 10, 2);
function woo_blocks_address_field_validation( WC_Order $order, $request ) {
$billing_address = $order->get_address('billing')['address_1'];
if ( $billing_address && ! preg_match( '/[0-9]+/', $billing_address ) ) {
throw new Exception( 'Your billing address must contain a house number!' );
}
}
@woogists
woogists / woo-blocks-check-house-number-in-shipping-address.php
Last active Nov 2, 2022
[WooCommerce Blocks] Check if the shipping address contains a house number
View woo-blocks-check-house-number-in-shipping-address.php
<?php
add_action( 'woocommerce_store_api_checkout_update_order_from_request', 'woo_blocks_address_field_validation', 10, 2);
function woo_blocks_address_field_validation( WC_Order $order, $request ) {
$shipping_address = $order->get_address('shipping')['address_1'];
if ( $shipping_address && ! preg_match( '/[0-9]+/', $shipping_address ) ) {
throw new Exception( 'Your shipping address must contain a house number!' );
}
}
@woogists
woogists / woocommerce_add_to_cart_button_text.php
Last active Feb 21, 2022
Change the 'Add to Cart' button text on either single product or archives pages.
View woocommerce_add_to_cart_button_text.php
<?php
// Change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_add_to_cart_button_text_single' );
function woocommerce_add_to_cart_button_text_single() {
return __( 'Add to Cart Button Text', 'woocommerce' );
}
// Change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_add_to_cart_button_text_archives' );