29 May 2020

How to use PHP session in wordpress

Use PHP session in wordpress.


add_action('init', 'myStartSession', 1);
function myStartSession() {
    if(!session_id()) {
        session_start();
    }
}

28 May 2020

How to add button next to add button in shop page in woo-commerce?

Add button next to add button in shop page in woo-commerce.


add_action( 'woocommerce_after_shop_loop_item', 'view_product_button_shop', 10 );

 

function view_product_button_shop() {

global $product;

$link = $product->get_permalink();

echo '<a href="' . $link . '" class="button addtocartbutton">View Product</a>';

}

27 May 2020

How to add new file type to upload in wordpress?

Add new file type to upload in wordpress


function add_file_types_to_uploads($file_types){
$new_filetypes = array();
$new_filetypes['svg'] = 'image/svg+xml';
$file_types = array_merge($file_types, $new_filetypes );
return $file_types;
}
add_filter('upload_mimes', 'add_file_types_to_uploads');

How to create custom wordpress logout button(wp_logout_url) in wordpress?

custom wordpress logout button(wp_logout_url) in wordpress




<li class="menu-logout"><a href="<?php echo wp_logout_url(); ?>"><span><i class="fa fa-sign-out"></i></span>Logout</a></li>




Or


<li class="signOut"><?php wp_logout(); ?></li>

add_action( 'wp_logout', 'auto_redirect_external_after_logout');
function auto_redirect_external_after_logout(){
  wp_redirect( 'http://redirect-url' );
  exit();
}



How to redirect user on different page accounding to user (Customer, editor, admin, subscriber and etc)?

How to redirect user on different page accounding to user (Customer, editor, admin, subscriber and etc)?


function wc_custom_user_redirect( $redirect, $user ) {
// Get the first of all the roles assigned to the user
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );
if( $role == 'administrator' ) {
    //Redirect administrators to the dashboard
    $redirect = $dashboard;
} elseif ( $role == 'shop-manager' ) {
    //Redirect shop managers to the dashboard
    $redirect = $dashboard;
} elseif ( $role == 'editor' ) {
    //Redirect editors to the dashboard
    $redirect = $dashboard;
} elseif ( $role == 'author' ) {
    //Redirect authors to the dashboard
    $redirect = $dashboard;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
    //Redirect customers and subscribers to the "My Account" page
    if(has_active_subscription($user->ID) || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')){
$redirect = home_url('/start-deal/');
}
else
{
$redirect = home_url('/pricing/');
}
} else {
    //Redirect any other role to the previous visited page or, if not available, to the home
    $redirect = wp_get_referer() ? wp_get_referer() : home_url();
}
return $redirect;
}

add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );

Check if User Has Already Purchased Product in woo-commerce?


WooCommerce: Check if User Has Already Purchased Product



function start_deal_button(){
ob_start();
global $user;


global $product;
$current_user = wp_get_current_user();

if(!is_user_logged_in())
{
echo "<a href='".site_url().'/my-account'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";
}

if((has_active_subscription() || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')) && (is_user_logged_in())){ 
    echo "<a href='".site_url().'/start-deal'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";;
}

if(!(has_active_subscription() || wc_customer_bought_product( $current_user->user_email, $current_user->ID,'9011')) && (is_user_logged_in())){
    echo "<a href='".site_url().'/pricing/'."' class='start-deal-button'>Start Deal  <i class='fa fa-handshake'></i></a>";

}

$obc = ob_get_contents();
ob_end_clean();
return $obc;
}
add_shortcode("startdeal","start_deal_button");

How to remove and unremove options(Download, Account Detail, Payment methods) from my account in woo-commerce?

How to remove and keep options(Download, Account Detail, Payment methods)  from my account in woo-commerce?





add_filter ( 'woocommerce_account_menu_items', 'misha_remove_my_account_links' );
function misha_remove_my_account_links( $menu_links ){

//unset( $menu_links['edit-address'] ); // Addresses


unset( $menu_links['dashboard'] ); // Remove Dashboard
//unset( $menu_links['payment-methods'] ); // Remove Payment Methods
unset( $menu_links['orders'] ); // Remove Orders
//unset( $menu_links['downloads'] ); // Disable Downloads
//unset( $menu_links['edit-account'] ); // Remove Account details tab
//unset( $menu_links['customer-logout'] ); // Remove Logout link

return $menu_links;

}

How to add re-captcha v3 on all Elementor forms using coding?

 Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){     ?> <script src="https://www...