Skip to content

Instantly share code, notes, and snippets.

Avatar

WooGists woogists

View GitHub Profile
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 Apr 20, 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' );
@woogists
woogists / change-checkout-urls-to-product-urls.php
Created Apr 26, 2021
For the Facebook for WooCommerce extension. By default, the link that is shared with Facebook is an “Add to Cart” URL for your product to speed up the checkout process. You may want this to be the product URL for a number of reasons. If so, you can use this code snippet to send the product URL to Facebook instead - https://docs.woocommerce.com/d…
View change-checkout-urls-to-product-urls.php
<?php // only copy this line if needed
/**
* Change checkout URLs to product URLs for Facebook products
*/
function sv_fbw_checkout_url_to_product( $product_data, $id ){
$product_data['checkout_url'] = $product_data['url'];
View woocommerce-usps-letters-and-envelopes.php
<?php
/**
* Add letters and envelopes to international services.
*/
add_filter( 'wc_usps_services', function( $services ) {
$services['I_FIRST_CLASS']['services']['13'] = "First Class Mail&#0174; International Letters";
$services['I_FIRST_CLASS']['services']['14'] = "First Class Mail&#0174; International Large Envelope";
return $services;
@woogists
woogists / functions.php
Last active Feb 21, 2022
[WooCommerce Bookings]: Set custom Google client ID and secret
View functions.php
<?php
/**
* Update Google client with your own application's cliend ID and secret from the Google Developer's Console.
*/
add_action(
'woocommerce_bookings_update_google_client',
function ( Google_Client $client ) {
$client->setClientId( 'YourClientIDFromGoogleDevelopersConsole' );
$client->setClientSecret( 'YourClientIDFromGoogleDevelopersConsole' );
View gist:482a79494f6def6b127326af5057b0d6
<?php
add_filter( 'wc_shipment_tracking_get_providers' , 'wc_shipment_tracking_add_custom_provider' );
/**
* wc_shipment_tracking_add_custom_provider
*
* Adds custom provider to shipment tracking
* Change the country name, the provider name, and the URL (it must include the %1$s)
* Add one provider per line