Skip to content

Instantly share code, notes, and snippets.

View slash1andy's full-sized avatar

Andrew Wikel slash1andy

View GitHub Profile

Smart Fixed Header

The gist? Slide the header up on scroll down, and slide it back into fixed position once the user scrolls back up. Super simple, yet super effective. Options include setting how many pixels from the top of the page to initialize (delay) and sensitivity (sensitivity).

Forked from Kyle Foster's Pen Smart Fixed Header.

A Pen by Secret Sam on CodePen.

License.

@slash1andy
slash1andy / gist:970f81db419eb01c9761
Last active September 27, 2017 04:04
WooCommerce Redirect to Custom URL Based on Product Purchased
function wcs_redirect_product_based ( $order_id ){
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
$_product = wc_get_product( $item['product_id'] );
// Add whatever product id you want below here
if ( $item['product_id'] == 70 ) {
// change below to the URL that you want to send your customer to
wp_redirect('http://www.yoururl.com/your-thank-you-page');
}
@slash1andy
slash1andy / gist:e69d5a68c205129b8cdd
Created June 19, 2015 04:15
WooCommerce Change Add to Cart Link and Text
//* Change the Add to Cart Text
add_filter( 'woocommerce_product_add_to_cart_text' , 'woo_woocommerce_product_add_to_cart_text' );
function woo_woocommerce_product_add_to_cart_text() {
global $product;
$product_type = $product->product_type;
switch ( $product_type ) {
case 'external':
@slash1andy
slash1andy / gist:45f5978d399859f4ee6e
Created June 29, 2015 21:00
WooCommerce Getting totals and rounding for paying commissions
$line_total = $order->get_line_total( $item, true );
$receiver_total = round( $line_total / 100 * $receiver[1], 2 );
@slash1andy
slash1andy / gist:caa198525d5dd1e51a81
Created July 10, 2015 03:28
Replace Default WooCommerce PayPal Accepted Cards Image
function replacePPIcon($iconUrl) {
return get_bloginfo('stylesheet_directory') . '/images/Cards.png';
}
add_filter('woocommerce_paypal_icon', 'replacePPIcon');
@slash1andy
slash1andy / gist:dd4e958f0ed2f686a07317a295a93f79
Created November 22, 2022 21:02
Discount Specific WooCommerce Payment Method (BTCPay in this example)
add_action( 'woocommerce_cart_calculate_fees','ts_add_discount', 20, 1 );
function ts_add_discount( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
// Mention the payment method e.g. cod, bacs, cheque or paypal
$payment_method = 'btcpaygf_default';
// The percentage to apply
$percent = 2; // 2%
$cart_total = $cart_object->subtotal_ex_tax;
$chosen_payment_method = WC()->session->get('chosen_payment_method'); //Get the selected payment method
@slash1andy
slash1andy / send-all-order-contents.php
Created April 24, 2023 17:17
Sends all order contents in WooCommerce webhook when using action.woocommerce_order_status_processing webhook
**
* Set the proper resource payload for a custom action webhook
*
* @param int $target_webhook_id
* @param string $desired_resource 'order', 'product', 'coupon', or 'customer'
*/
function set_resource_for_webhook_payload_by_webhook_id($target_webhook_id, $desired_resource) {
// Set the desired_resource payload for this webhook ('order', 'product', 'coupon', 'customer')
add_filter('woocommerce_webhook_resource', function($resource, $webhook_id) use ($target_webhook_id, $desired_resource) {