Showing posts with label WooCommerce. Show all posts
Showing posts with label WooCommerce. Show all posts

Monday, April 15, 2024

How to display category description on first page only?

add_action( 'wp', function() {

    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;

    if ( 1 !== $page ) {

        remove_action( 'woocommerce_archive_description', 'shoptimizer_woocommerce_taxonomy_archive_description' );

        remove_action( 'woocommerce_archive_description', 'shoptimizer_category_image', 20 );

        // If you also want to remove the "Below category content" area:

        remove_action( 'woocommerce_after_shop_loop', 'shoptimizer_product_cat_display_details_meta', 40 );

    };

}, 20 ); 

Monday, February 26, 2024

How to increase Logout session With AJAX in WordPress

function login_session_expired() {
// we only care to add scripts and styles if the user is logged in.
if ( is_user_logged_in() ) {

// add javascript file
wp_register_script( 'wp_auth_check', '/wp-includes/js/wp-auth-check.js' , array('heartbeat'), false, 1);
wp_localize_script( 'wp_auth_check', 'authcheckL10n', array(
'beforeunload' => __('Your session has expired. You can log in again from this page or go to the login page.'),
'interval' => apply_filters( 'wp_auth_check_interval', 1 * MINUTE_IN_SECONDS ), // default interval is 3 minutes
) );
wp_enqueue_script ('wp_auth_check');
// add css file
wp_enqueue_style( 'wp_auth_check','/wp-includes/css/wp-auth-check.css', array( 'dashicons' ), NULL, 'all' );
// add the login html to the page
add_action( 'wp_print_footer_scripts', 'wp_auth_check_html', 5 );
}
}
add_action( 'wp_enqueue_scripts', 'login_session_expired' );
// make sure the stylesheet appears on the lightboxed login iframe
function login_session_expired_styles() {
wp_enqueue_style( 'wp_auth_check','/wp-includes/css/wp-auth-check.css', array( 'dashicons' ), NULL, 'all' );
}
add_action( 'login_enqueue_scripts', 'login_session_expired_styles' );

Thursday, November 2, 2023

Woocommerce custom user redirect

 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 == 'seller' ) {
        $redirect = site_url()."/dashboard";
    }elseif ( $role == 'sales' ) {
        //Redirect Sales team to the dashboard
        $redirect = $dashboard;
    }elseif ( $role == 'editor' ) {
        $redirect = home_url();
    } elseif ( $role == 'author' ) {
        $redirect = home_url();
    } elseif ( $role == 'customer' || $role == 'subscriber' ) {
        //Redirect customers and subscribers to the "My Account" page
        $redirect = $myaccount;
    } 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 );

Sunday, June 25, 2023

Custom Tabs in WooCommerce Account page

 function ac_add_my_custom_endpoint() {
    add_rewrite_endpoint( 'custom-tab', EP_ROOT | EP_PAGES );
}
  
add_action( 'init', 'ac_add_my_custom_endpoint' );

/*/*/*/*/*/*
function ac_add_custom_query_vars( $vars ) {
    $vars[] = 'custom-tab';
    return $vars;
}
  
add_filter( 'query_vars', 'ac_add_custom_query_vars', 5 );

/*/*/*/*/*/*/*/

function ac_add_custom_menu_item_my_account( $items ) {
    $items['custom-tab'] = 'Custom Tab';
    return $items;
}
  
add_filter( 'woocommerce_account_menu_items', 'ac_add_custom_menu_item_my_account' );

/*/*/*/*/

function ac_custom_tab_content_my_account() {
   echo 'Go Back to <a href="https://Eaxmple.com/">Custom Website</a>';
}
  
add_action( 'woocommerce_account_custom-tab_endpoint', 'ac_custom_tab_content_my_account' );

/*/*/*/*/*

Tuesday, May 16, 2023

Notification to any email address with add to cart woocommerce

 add_action( 'woocommerce_add_to_cart', 'cwpai_woo_send_email_to_admin_on_add_to_cart', 10, 6 );

function cwpai_woo_send_email_to_admin_on_add_to_cart( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {

  

    $product      = wc_get_product( $product_id );

    $product_name = $product->get_name();

    if ( isset( $_POST['add-to-cart']) ) {

    $company_name =  $_POST['membership_company_name'];

    $contact_person =  $_POST['membership_contact_person'];

    $membership_address =  $_POST['membership_address'];

    $membership_city_town =  $_POST['membership_city_town'];

    $province =  $_POST['province'];

    $postal_code =  $_POST['postal_code'];

    $wcb =  $_POST['wcb'];

    $industry_code_s =  $_POST['industry_code_s'];

    $cor =  $_POST['cor'];

    $expiry_date =  $_POST['expiry_date'];

    $if_your =  $_POST['if_your'];

    }

$data = "<table style='width:50%' cellpadding='5'><tr>

   <th>Item</th>

   <th>Description</th>

   </tr><tr>

   <td>Name</td>

   <td>$product_name</td>

   </tr>

   <tr>

   <td>Company Name:</td>

   <td>$company_name</td>

   </tr>

   <tr>

   <td>Address</td>

   <td>$membership_address</td>

   </tr>

   <tr>

   <td>City/Town</td>

   <td>$membership_city_town</td>

   </tr>

   <tr>

   <td>Province</td>

   <td>$province</td>

   </tr>

   <tr>

   <td>Postal Code</td>

   <td>$postal_code</td>

   </tr>

   <tr>

   <td>WCB #</td>

   <td>$wcb</td>

   </tr>

   <tr>

   <td>Industry Code(s)</td>

   <td>$industry_code_s</td>

   </tr>

   <tr>

   <td>C.O.R #</td>

   <td>$cor</td>

   </tr>

   <tr>

   <td>Expiry Date</td>

    <td>$expiry_date</td>

   </tr>

   <tr>

    <td>If your company has ever registered with another Certifying Partner please name</td>

    <td>$if_your</td>

    </tr></table>";


$headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail( 'example@gmail.com', 'New notification', $data, $headers );

 

}


1 hour Free Service for WordPress website :)

      1 hour Free Service for WordPress website :)