Home

Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Tuesday, December 4, 2018

How to add custom fields in ultimate profile page ?

add_action('um_after_account_general', 'showExtraFields', 100);

function showExtraFields(){

$custom_fields = [
"phone" => "Phone",
"Age" => "Age"
];

$fields = [];
foreach ($custom_fields as $key => $value) {
$fields[$key] = array(
'title' => $value,
'metakey' => $key,
'type' => 'text',
'label' => $value,
'required' => 1,
'public' => 1,
'editable' => 1,
'validate' => $key
);
}

$id = um_user('ID');
$fields = apply_filters( 'um_account_secure_fields', $fields, $id );

UM()->builtin()->saved_fields = $fields;
UM()->builtin()->set_custom_fields();

foreach( $fields as $key => $data )
$output .= UM()->fields()->edit_field( $key, $data );

echo $output;
}

add_action( 'um_submit_account_errors_hook', 'my_submit_account_errors', 10, 1 );
function my_submit_account_errors( $submitted ) {

global $ultimatemember;
if (strlen($submitted['phone'] ) > 9)
$ultimatemember->classes['form']->add_error('phone','Phone is too long');
}

Friday, January 12, 2018

How to remove woocommerce breadcrumb from product page ?

Add the following line of code to the WordPress theme functions.php file:

remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);

add_action('template_redirect', 'remove_shop_breadcrumbs' );
function remove_shop_breadcrumbs(){
if (is_single()) {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0);
}
}

Friday, January 23, 2015

How to add product in woocommerce using programmatically with wpml

function woocommerce_add_products_dynamicaly()
 {
        //empty cart
        global $woocommerce;
        $woocommerce->cart->empty_cart();
        // Remove default cart message
        $woocommerce->clear_messages();
       
        //price
        $invoiceprice = 1;
       
        //Generate title
        $timestampedtitle = rand()." Date: ".date("d/m/Y")." Amount: £".$invoiceprice;
       
        //Generate message
        $message = date_timestamp_get(date_create())." Date: ".date('m/d/Y h:i:s a', time())." Invoice amount: £".$invoiceprice;

        $post = array(
        'post_author' => '2',
        'post_status' => "publish",
        'post_title' => $timestampedtitle,
        'post_content' => $message,
        'post_parent' => '',
        'post_type' => "product",
        //'post_status' => 'private',
        );

Monday, October 6, 2014

Change and Update WordPress URLS in Database When Site is Moved to new Host

 
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

Thursday, January 2, 2014

WooCommerce : How to Disable Shopping Cart Function

Step : 1 :-  Open header.php file of your current theme and Add this css code.

/*disabled shopping cart function for woocommerce*/
#wrap_all .sub_menu {
 display:none;
}
 
.woocommerce-message {
 display:none;
}
 
.thumbnail_container div.thumbnail_container_inner a.product_type_variable,
.thumbnail_container div.thumbnail_container_inner a.product_type_simple {
 display:none;
}
 
.quantity {
 display:none;
}
 
.summary button {
 display:none;
}
 
.summary button[type="submit"] {
 display:none;
}
 
.cart_dropdown {
 display:none;
}
 
/*Custom styling for Mystile theme*/
ul.nav li.cart a,
ul.nav li.checkout a {
display:none;
}
  

Step : 2 :-  Open function.php file of your current theme and Add this hook code.
 
// Remove add to cart button on the navigation bar
remove_action( 'woo_nav_after', 'wootique_cart_button', 10);
remove_action( 'woo_nav_after', 'wootique_checkout_button', 20);
 
// Remove add to cart button from the product loop
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10, 2);
 
// Remove add to cart button from the product details page
remove_action( 'woocommerce_before_add_to_cart_form', 'woocommerce_template_single_product_add_to_cart', 10, 2);
 
//disabled actions (add to cart, checkout and pay)
remove_action( 'init', 'woocommerce_add_to_cart_action', 10);
remove_action( 'init', 'woocommerce_checkout_action', 10 );
remove_action( 'init', 'woocommerce_pay_action', 10 );
 
// check for clear-cart get param to clear the cart
add_action( 'init', 'woocommerce_clear_cart_url' );
function woocommerce_clear_cart_url()
{   
    global $woocommerce;
    $woocommerce->cart->empty_cart();   
}
 

Tuesday, December 17, 2013

Create a WordPress custom post type

In your theme’s functions.php file, insert the following code:
  
 // Create out post type
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
            $args = array(
            'labels' => post_type_labels( 'Book' ),
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'show_in_menu' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => null,
            'supports' => array('title',
                'editor',
                'author',
                'thumbnail',
                'excerpt',
                'comments'
            )
        );
   
            register_post_type( 'book', $args );
    }
   
    // A helper function for generating the labels
    function post_type_labels( $singular, $plural = '' )
    {
        if( $plural == '') $plural = $singular .'s';
     
        return array(
            'name' => _x( $plural, 'post type general name' ),
            'singular_name' => _x( $singular, 'post type singular name' ),
            'add_new' => __( 'Add New' ),
            'add_new_item' => __( 'Add New '. $singular ),
            'edit_item' => __( 'Edit '. $singular ),
            'new_item' => __( 'New '. $singular ),
            'view_item' => __( 'View '. $singular ),
            'search_items' => __( 'Search '. $plural ),
            'not_found' =>  __( 'No '. $plural .' found' ),
            'not_found_in_trash' => __( 'No '. $plural .' found in Trash' ),
            'parent_item_colon' => ''
        );
    }
   
    //add filter to ensure the text Book, or book, is displayed when user updates a book
    add_filter('post_updated_messages', 'post_type_updated_messages');
    function post_type_updated_messages( $messages ) {
            global $post, $post_ID;
   
            $messages['book'] = array(
                    0 => '', // Unused. Messages start at index 1.
                    1 => sprintf( __('Book updated. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
                    2 => __('Custom field updated.'),
                    3 => __('Custom field deleted.'),
                    4 => __('Book updated.'),
                    /* translators: %s: date and time of the revision */
                    5 => isset($_GET['revision']) ? sprintf( __('Book restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
                    6 => sprintf( __('Book published. <a href="%s">View book</a>'), esc_url( get_permalink($post_ID) ) ),
                    7 => __('Book saved.'),
                    8 => sprintf( __('Book submitted. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
                    9 => sprintf( __('Book scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview book</a>'),
                    // translators: Publish box date format, see php.net/date
                    date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
                    10 => sprintf( __('Book draft updated. <a target="_blank" href="%s">Preview book</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
            );
   
            return $messages;
    }

Monday, October 29, 2012

Structure Of A WordPress Theme


There are a couple different types of pages in WordPress. Each type of page can have a customized look and feel. This customization is done by templates. Templates are how themes work. Each template is a seperate PHP file inside the theme’s directory. Here are the standard templates:
  • 404 Template = 404.php – It’s handy to create a custom 404 page (Page Not Found) template. You can list common links and ways for users to find what they are looking for.
  • Archive Template = archive.php
  • Archive Index Page = archives.php
  • Comments Template = comments.php – This template defines how comments look under individual posts on the “Post Template”.
  • Footer Template = footer.php – HTML that is placed at the bottom of each page, saves you time and produces less duplicate HTML code in your templates.
  • Header Template = header.php – HTML that is placed at the top of each page, usually has the <head> section in it.
  • Links = links.php
  • Main Template = index.php – Usually this page lists your most recent posts. This is the “home” page of your site.
  • Page Template = page.php – Used for single pages, instead of blog posts. Your “About” page uses this template. This is the default page template, you can make your own custom page templates. I’ll cover this more in detail later.
  • Popup Comments Template = comments-popup.php
  • Post Template = single.php – This is where you customize pages that display single posts. Click on a post title (permalink) and you will be at it’s single post page using the post template.
  • Search Form = searchform.php
  • Search Template = search.php
  • Sidebar Template = sidebar.php – Usually the right hand side bar of the page. Some themes have more than one side bar so you’ll see templates like left_sidebar.php.
  • Stylesheet = style.css – Default place to put your CSS. It also contains the name and description of the theme. You must always have this file with the name and description of your theme. Many themes will have multiple CSS files that are linked to from the header.php file or the individual page templates to customize individual pages with different style rules.   

Thursday, October 18, 2012

Display submenu on left side on all pages

<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
    <?php echo $children; ?>
<?php } ?>

Friday, November 11, 2011

how to Auto-Login in wordpress

//determine WordPress user account to impersonate
$user_login = 'guest';

//get user's ID
$user = get_userdatabylogin($user_login);
$user_id = $user->ID;
  
//login
wp_set_current_user($user_id, $user_login);
wp_set_auth_cookie($user_id);
do_action('wp_login', $user_login);
     
?>
<script type="text/javascript">
window.location = "wp-admin/profile.php";
</script>
<?php 

Friday, July 1, 2011

In Wordpress Retrieves the information pertaining to the currently logged in user

<?php global $current_user;
      get_currentuserinfo();

      echo 'Username: ' . $current_user->user_login . "\n";
      echo 'User email: ' . $current_user->user_email . "\n";
      echo 'User first name: ' . $current_user->user_firstname . "\n";
      echo 'User last name: ' . $current_user->user_lastname . "\n";
      echo 'User display name: ' . $current_user->display_name . "\n";
      echo 'User ID: ' . $current_user->ID . "\n";
?>

In Wordpress Display content to registered users only

<?php global $user_login; get_currentuserinfo();
if ($user_login) :?>
<li><a href="your-uri-goes-here">Write a New Post</a></li>
<?php endif; ?>


This puts a link in to the write post page if the user is logged in. 
rathoddhirendra.blogspot.com-Google pagerank and Worth