Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / gist:e67d8e6c9d3bbf48dc266b8082798bda
Created April 29, 2022 07:52
[Conditional Shipping & Payments] Creating new conditions that include multiple modifiers
<?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 April 20, 2022 15:27
[WooCommerce Blocks] Check if the billing and shipping address contains a house number
<?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 April 20, 2022 15:49
[WooCommerce Blocks] Check if the billing address contains a house number
<?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 November 2, 2022 17:42
[WooCommerce Blocks] Check if the shipping address contains a house number
<?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 December 6, 2023 09:57
Change the 'Add to Cart' button text on either single product or archives pages.
<?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 April 26, 2021 05:51
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…
<?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'];
@woogists
woogists / woocommerce-usps-letters-and-envelopes.php
Last active December 29, 2023 19:51
USPS: Add Envelope as a service
<?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 October 7, 2023 17:39
[WooCommerce Bookings]: Set custom Google client ID and secret
<?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' );
<?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
@woogists
woogists / gist:9bd427bdf92e966d7f368355f97e17b2
Created March 20, 2019 22:39
Bookings REST API Bookings JSON Response
[
{
"all_day": true,
"cost": "100",
"customer_id": 1,
"date_created": 1551471271,
"date_modified": 1551593795,
"end": 1551571199,
"google_calendar_event_id": "uhd8bir3raajo4tco365foii1o",
"order_id": 154167,