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
Last active August 30, 2023 14:30
Redirect user to cart page when they login
/**
* WordPress function for redirecting users on login based on user role
*/
function awp_login_redirect_callback( $url, $request, $user ) {
/*
* Add your custom url
*/
$url = home_url( '/cart/' );
return $url;
@raftaar1191
raftaar1191 / functions.php
Last active August 7, 2023 12:42
Add text on the user profile page after the nickname is displayed
/**
* Print custom text on the profile page after the nickname
*/
function awp_bp_before_member_header_meta_callback() {
echo "Custom Text";
}
add_action( 'bp_before_member_header_meta', 'awp_bp_before_member_header_meta_callback' );
@raftaar1191
raftaar1191 / functions.php
Created June 7, 2023 15:47
Change the default template of page and post to something else
/**
* Change the default template to elementor_header_footer for new page and post
*/
function bb_rest_set_default_page_template( $data, $post ) {
if (
0 != count( get_page_templates( $post ) )
&& get_option( 'page_for_posts' ) != $post->ID
&& '' == $data->data['template']
) {
@raftaar1191
raftaar1191 / functions.php
Created May 15, 2023 11:19
Remove gutenbur and wp-editor from Specific page
function use_block_editor_for_post_disable_gutenberg( $can_edit, $post ) {
if( $post->ID == '247' ) {
return false;
}
return true;
}
add_filter( 'use_block_editor_for_post', 'use_block_editor_for_post_disable_gutenberg', 10, 2 );
@raftaar1191
raftaar1191 / functions.php
Last active May 15, 2023 10:55
Add custom link into the User Profile Menu of BuddyBoss
function bp_member_options_nav_custom_link() {
?>
<li id="custom-link-li" class="bp-personal-tab">
<a href="/members/admin/invites/" id="custom-link" class="">
<div class="bb-single-nav-item-point">Custom Text</div>
</a>
</li>
<?php
}
add_action( 'bp_member_options_nav', 'bp_member_options_nav_custom_link', 100 ); //Priority must be higher than 10
@raftaar1191
raftaar1191 / functions.php
Created May 15, 2023 09:56
Change homepage for the login and non-login user
/**
* Add condition to check if the user is login and non-login
* Notes: Make sure to set the login user homepage as the default homepage in the Admin Dashboard -> Settings-> Reading
*/
function change_the_homepage_for_non_login_user() {
if ( ! is_admin() && ! is_user_logged_in() ) {
add_filter( 'pre_option_page_on_front', 'pre_option_page_on_front_homepage_for_non_login_user' );
}
}
add_action( 'init', 'change_the_homepage_for_non_login_user' );
@raftaar1191
raftaar1191 / functions.php
Last active April 4, 2023 17:17
Update All LearnDash courses price by using mysql statement
Main query run on the live site:
Chagne the open to paynow
UPDATE wpig_postmeta as pm
SET pm.meta_value = 'paynow'
WHERE pm.meta_key = '_ld_price_type';
For 300:
@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