Skip to content

Instantly share code, notes, and snippets.

View raftaar1191's full-sized avatar
🏠
Working from home

Deepak Gupta raftaar1191

🏠
Working from home
View GitHub Profile
@raftaar1191
raftaar1191 / functions.php
Created March 10, 2023 13:24
Redirect the user to checkout page when user try to visit the cart page
function gbol_template_redirect_cart_redirect( $permalink ) {
$cart_id = wc_get_page_id('cart');
$checkout_id = wc_get_page_id('checkout');
/**
* Skip if this is not a cart page
*/
if ( $cart_id == $checkout_id ) {
return;
}
@raftaar1191
raftaar1191 / functions.php
Created March 10, 2023 13:12
Find Default Product Variation from WooCommerce
function find_matching_product_variation( $product ) {
$is_default_variation = false;
$default_attributes = $product->get_default_attributes();
foreach($product->get_available_variations() as $variation_values ){
foreach($variation_values['attributes'] as $key => $attribute_value ){
$attribute_name = str_replace( 'attribute_', '', $key );
$default_value = $product->get_variation_default_attribute($attribute_name);
if( $default_value == $attribute_value ){
$is_default_variation = true;
@raftaar1191
raftaar1191 / functions.php
Created February 28, 2023 04:33
removing the product from the cart after a while?
add_filter('wc_session_expiring', 'so_26545001_filter_session_expiring' );
function so_26545001_filter_session_expiring($seconds) {
return 60 * 2; // 2 mints
}
add_filter('wc_session_expiration', 'so_26545001_filter_session_expired' );
function so_26545001_filter_session_expired($seconds) {
return 60 * 3; // 3 mints
@raftaar1191
raftaar1191 / functions.php
Created February 27, 2023 11:12
Add class into the body tag to check if user is login or logout
/**
* Function to add class when user is login in or not login in
*/
function awp_body_class_callback( $classes ) {
$class = get_current_user_id() ? 'user-login' : 'user-logout';
return array_merge( $classes, array( $class ) );
}
add_filter( 'body_class', 'awp_body_class_callback', 10, 1 );
@raftaar1191
raftaar1191 / functions.php
Created February 15, 2023 05:01
Do not allow the user to send the message when user client on the return button
/**
* Do not allow the user to send the message when they client on the return button
*/
function bb_wp_footer_callback() {
?>
<script type="text/javascript">
$( document ).ready(function() {
var el = document.getElementById( "message_content" );
el.addEventListener("keydown", function(event) {
if (event.key === "Enter" && ! event.shiftKey ) {
@raftaar1191
raftaar1191 / functions.php
Last active February 14, 2023 07:33
Always save the Stripe Credit card details Token into the site for later use
/**
* Always save card token for stripe: Save payment information to my account for future purchases.
*/
add_filter( 'wc_stripe_force_save_source', '__return_true' );
/**
* Filter the HTML of the stripe credit card details
*/
function payment_gateway_field_html_stripe_callback( $field_html ) {
$field_html = str_ireplace( '<fieldset', 'style=display:none; <fieldset', $field_html );
@raftaar1191
raftaar1191 / functions.php
Last active February 6, 2023 19:40
Carbon Fields knows if these is a hook that triggers before the field is saved and has both the new and old values
/**
* Get the value before the save run
*/
function carbon_fields_should_save_field_value_callback( $save, $value, $field ) {
$fields_id = 'crb_text';
error_log( print_r( carbon_get_theme_option( $fields_id ), true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new1.log' );
error_log( print_r( $value, true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new1.log' );
@raftaar1191
raftaar1191 / functions.php
Created December 8, 2021 18:55
karuna Code
/**
* Get the responce from the data cms
*/
function get_responce_data_cms_get( $url ) {
$param = array(
'timeout' => 30,
'headers' => array()
);
@raftaar1191
raftaar1191 / command-line
Created June 11, 2021 06:59
Move GIT comment, tag and branch from 1 repo to another
https://stackoverflow.com/questions/8538362/how-do-i-move-a-git-repo-from-beanstalk-to-github
# In this example, we use an external account named extuser and
# a GitHub account named ghuser to transfer repo.git
@raftaar1191
raftaar1191 / functions.php
Last active April 28, 2021 10:03
Change the Donation Receipt text in Receipt page of GiveWP
/**
* Call before the Donation Receipt text is display
*/
function give_custom_give_payment_receipt_header_before_callback() {
add_filter( 'gettext', 'child_give_text_switcher', 10, 3 );
}
add_action( 'give_payment_receipt_header_before', 'give_custom_give_payment_receipt_header_before_callback' );