Skip to content

Instantly share code, notes, and snippets.

View ashokrane's full-sized avatar

Vishal Kothari ashokrane

View GitHub Profile
@ashokrane
ashokrane / shorten-woocommerce-product-name-in-abandon-cart-recovery-emails.php
Created January 24, 2018 07:16
How to shorten WooCommerce product name in Abandon cart recover email notification
<?php
add_filter( 'wcap_product_name', 'shorten_product_name_in_abandon_cart_emails', 10, 1 );
function shorten_product_name_in_abandon_cart_emails( $item_name ) {
if ( 'Rent a bicycle' == $item_name ) {
$item_name = 'Rent a bicy..';
}
return $item_name;
}
@ashokrane
ashokrane / show_custom_woocommerce_thank_you_by_variation_id.php
Last active March 13, 2018 11:39
Redirect to custom WooCommerce Thank You page based on product attribute id (variation id)
<?php
add_action( 'woocommerce_thankyou', 'redirect_product_attribute_based', 1 );
function redirect_product_attribute_based( $order_id ) {
$order = wc_get_order( $order_id );
foreach( $order->get_items() as $item ) {
// Add whatever variation id you want below here
if ( isset( $item[ 'variation_id' ] ) && $item[ 'variation_id' ] == 446 ) {
// change below to the URL that you want to send your customer to
wp_redirect( 'http://yoururl.com/custom-thank-you/' );
@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/
*/
@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 / 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 / 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 / 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-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 / 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 / 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;