Skip to content

Instantly share code, notes, and snippets.

View ashokrane's full-sized avatar

Vishal Kothari ashokrane

View GitHub Profile
@ashokrane
ashokrane / show_custom_text_woocommerce_thank_you_by_variation_id.php
Created March 13, 2018 11:41
Print custom text on WooCommerce Thank You page based on product attribute id (variation id)
<?php
add_action( 'woocommerce_thankyou', 'show_custom_text_by_variation_id', 1 );
function show_custom_text_by_variation_id( $order_id ) {
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Add whatever variation id you want below here. My attributes are Cheddar, Mozarella & Swiss
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 446 ) {
echo 'Thank you for choosing Cheddar cheese. Enjoy your Sandwich!<br/>';
}
@ashokrane
ashokrane / seasonal-addon-price-on-cart-checkout-page.php
Created January 19, 2022 13:05
Seasonal Addon Price on Cart & Checkout page
function bkap_woocommerce_cart_item_subtotal( $product_subtotal, $cart_item, $cart_item_key ) {
if ( isset( $cart_item['bkap_booking'] ) ) {
$booking = $cart_item['bkap_booking'][0];
if ( isset( $booking[ 'hidden_date_checkout' ] ) ) {
$checkin_date_str = strtotime( $booking[ 'hidden_date' ] );
$checkout_date_str = strtotime( $booking[ 'hidden_date_checkout' ] );
$checkin_date = date( 'Y-m-d', $checkin_date_str );
$checkout_date = date( 'Y-m-d', $checkout_date_str );
@ashokrane
ashokrane / code2.gs
Created July 19, 2019 22:07
Google apps script for integration of WooCommece orders to Google sheets.
//this is a function that fires when the webapp receives a GET request
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var order_number = myData.number;
var order_created = myData.date_created;
@ashokrane
ashokrane / code.gs
Created July 17, 2019 12:08
Google script for listening to WooCommerce Webhook & parse order information to add to Google sheet
//this is a function that fires when the webapp receives a GET request
function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}
//this is a function that fires when the webapp receives a POST request
function doPost(e) {
var myData = JSON.parse([e.postData.contents]);
var order_number = myData.number;
var order_created = myData.date_created;
@ashokrane
ashokrane / woocommerce-order-data-via-webhook.json
Last active July 19, 2019 20:43
WooCommerce Order data sent via order.created webhook action
{
"id":1194,
"parent_id":0,
"number":"1194",
"order_key":"wc_order_YzXqv7u79WjZS",
"created_via":"checkout",
"version":"3.6.4",
"status":"on-hold",
"currency":"USD",
"date_created":"2019-07-20T02:08:30",
@ashokrane
ashokrane / overwrite-step-minute-increment.php
Created March 30, 2019 12:18
Overwrite the minute increment from 5 minutes to anything else in Order Delivery Datea plugin
<?php
add_filter( 'orddd_time_slider_minute_step', 'ts_orddd_overwrite_minute_increment', 10, 1 );
function ts_orddd_overwrite_minute_increment( $step_minute ) {
$step_minute = 15;
return $step_minute;
}
@ashokrane
ashokrane / woocommerce-specific-date-filters-by-variations.php
Created March 30, 2019 09:49
Sample functions for specific date filters in Order Delivery Date Pro plugin
<?php
add_filter( 'orddd_global_specific_delivery_dates', 'ts_add_global_specific_delivery_charges_by_variations', 10, 4 );
function ts_add_global_specific_delivery_charges_by_variations( $specific_fees, $specific_date, $specific_date_charges, $specific_charges_label ) {
global $woocommerce;
$found = false;
// determine if selected variation is in cart or not
@ashokrane
ashokrane / strtotime_returning_blank.php
Created February 23, 2019 12:45
strtotime() returning blank or empty timestamp
<?php
echo strtotime( '21-02-2019 10:0' ); // 1550743200
echo '<br>' . strtotime( '21-02-2019 10:00' ); // 1550743200
echo '<br>' . strtotime( '21-02-2019 100' ); // blank, thereby results in a date of 1-1-1970 when used in date()
echo '<br>' . strtotime( '21-02-2019 1000' ); // 1550743200
@ashokrane
ashokrane / add-delivery-date-field.php
Created February 22, 2019 16:14
Add delivery date field on WooCommerce checkout page
<?php
add_action( 'woocommerce_after_checkout_billing_form', 'display_extra_fields_after_billing_address' , 10, 1 );
function display_extra_fields_after_billing_address () {
_e( "Delivery Date: ", "add_extra_fields");
?>
<br>
<input type="text" name="add_delivery_date" class="add_delivery_date" placeholder="Delivery Date">
<?php
}
@ashokrane
ashokrane / edd-extra-api-endpoints.php
Last active January 13, 2019 10:14
Fetch sales & earnings (or refunded sales & earnings) for different products, date-wise - for Easy Digital Downloads
<?php
/*
Plugin Name: Extra API Endpoints for Easy Digital Downloads
Plugin URI: https://www.tychesoftwares.com
Description: This plugin allows to fetch some additional statistics for your Easy Digital Downloads store.
Author: Tyche Softwares
Version: 1.0
Author URI: http://www.tychesoftwares.com/about
Contributor: Tyche Softwares, http://www.tychesoftwares.com/
*/