Skip to content

Instantly share code, notes, and snippets.

View sarathlal-old's full-sized avatar
🎯
Focusing

Sarathlal N sarathlal-old

🎯
Focusing
View GitHub Profile
@sarathlal-old
sarathlal-old / gist:e7c0d3b1e094d943769dd569bccf385e
Created March 19, 2021 07:18
Only allow 1 item in WooCommerce Cart
// before add to cart, empty the existing cart items
add_filter( 'woocommerce_add_to_cart_validation', 'sa53re_custom_woocommerce_add_to_cart_validation' );
function sa53re_custom_woocommerce_add_to_cart_validation( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
// Do nothing with the data and return
return true;
Only add items in a category group only in to cart - WooCommerce 4
function sa45er_category_group_validation($valid, $product_id, $quantity) {
global $woocommerce;
if($woocommerce->cart->cart_contents_count == 0){
return $valid;
}
$target_cat_group = array(
array(17,20), // Update your product category
@sarathlal-old
sarathlal-old / gist:826ff166f743b8cd527ae49a327e06ae
Last active August 16, 2020 11:08
Dohabank - mastercard - WooCommerce
<?php
/**
* Loading text domain
*/
function load_woo_mpgs_textdomain() {
load_plugin_textdomain( 'woo-mpgs', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'load_woo_mpgs_textdomain' );
HSTORE in flask app
In your model, import requred module
from sqlalchemy.dialects.postgresql import HSTORE
from sqlalchemy.ext.mutable import MutableDict
Then use Hstore in our model class
class Submission(db.Model):
@sarathlal-old
sarathlal-old / wrap-paragraphs.js
Created July 31, 2019 06:57 — forked from kavanagh/wrap-paragraphs.js
Wrap an array of strings with p tags
var paragraphs = ['paragraph 1', 'paragraph 1'];
var html = '<p>' + paragraphs.join('</p><p>') + '</p>';
/*
* For latest WooCommerce Rest API
* Add a referanse field to the Order API response.
*/
function prefix_wc_rest_prepare_order_object( $response, $object, $request ) {
// Get the value
$referanse_meta_field = ( $value = get_post_meta($object->get_id(), '_billing_referanse', true) ) ? $value : '';
$response->data['referanse'] = $referanse_meta_field;
Why WordPress not using session in PHP. Reason and the better alternatives.
https://pressjitsu.com/blog/wordpress-sessions-performance/
https://techgirlkb.guru/2017/08/wordpress-doesnt-use-php-sessions-neither/
@sarathlal-old
sarathlal-old / gist:22a003f3965eaae40b3fe6b32812c36c
Last active July 27, 2018 13:53
Get WoCommerce orders of a specific customer
$customer_id = get_current_user_id();
$customer_orders = get_posts( array(
'numberposts' => -1,
'meta_key' => '_customer_user',
'meta_value' => $customer_id,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
//'post_status' => array('wc-completed'),
) );
@sarathlal-old
sarathlal-old / Gmail SMTP & WordPress
Last active April 4, 2019 05:26
Configure Gmail account & SMTP plugin to send SMTP emails from WordPress
1. Install SMTP Plugins
https://wordpress.org/plugins/search/SMTP/
2. Configure Plugins
* Outgoing Mail (SMTP) Server: smtp.gmail.com
* Use Authentication: Yes
* Use Secure Connection: Yes (TLS or SSL)
* Username: your Gmail account (e.g. user@gmail.com)
<?php
/*
Template Name: archive
*/
get_header();
wp_enqueue_script('magnific');
add_action('wp_footer', 'san_scripts', 21);
function san_scripts() {