Skip to main content

Posts

Showing posts from June, 2020

How create and show meta (custom) fields in wordpress posts ?

How create meta (custom) fields in wordpress posts ? <?php /**  * Register meta boxes.  */ function meta_register_meta_boxes() {     add_meta_box( 'meta-1', __( 'Custom Field', 'meta' ), 'meta_display_callback', 'contracts' ); } add_action( 'add_meta_boxes', 'meta_register_meta_boxes' ); /**  * Meta box display callback.  *  * @param WP_Post $post Current post object.  */ function meta_display_callback( $post ) { ?> <div class="meta_box">     <style scoped>         .meta_box{             display: grid;             grid-template-columns: max-content 1fr;             grid-row-gap: 10px;             grid-column-gap: 20px;         }         .meta_field{             display: contents;         }     </style>     <p class="meta-options meta_field">         <label for="meta_author">Author</label>         <input id="meta_

How to add custom woocommerce-MyAccount-navigation on woocommerce account page

// Note the low hook priority, this should give to your other plugins the time to add their own items... add_filter( 'woocommerce_account_menu_items', 'add_my_menu_items', 99, 1 ); function add_my_menu_items( $items ) {     $my_items = array(     //  endpoint   => label         '2nd-item' => __( '2nd Item', 'my_plugin' ),         '3rd-item' => __( '3rd Item', 'my_plugin' ),     );     $my_items = array_slice( $items, 0, 1, true ) +         $my_items +         array_slice( $items, 1, count( $items ), true );     return $my_items; }

How to create custom meta boxes on single product page in woocommerce?

Create custom meta boxes on single product page in woocommerce. /**  * Display custom field on the front end  * @since 1.0.0  */ function wpcodekit_display_custom_field() { ?> <style> .custom-field-container {     float: left;     justify-content: center;     align-items: center;     max-width: 99px;     padding: 0px 10px;     text-align: center; } img.custom-field-icons {     margin: auto;     width: 25px;     margin-bottom: 0px; } .custom-field-outer {     margin-bottom: 25px;     float: left;     width: 100%; } .custom_field_title {     font-size: 12px;     line-height: 0px !important;     color: #2d2d2d; } .cfwc-custom-field-wrapper {     line-height: 16px; } </style> <?php  global $post;  // Check for the custom field value  $product = wc_get_product( $post->ID );  $title_one = $product->get_meta( 'replacement_Days' );  $title_two = $product->get_meta( 'year_warranty' );  $title_three =

How to create custom social share button in wordpress without plugin?

Create custom social share button in wordpress without plugin. function social_icons_products(){ global $wpdb; global $post;  $full_line = get_permalink();  $slug = basename(get_permalink());     // $url = str_replace("/", "%2F", $full_line);     // $url = str_replace(":", "%3A", $url);      ?> <style> .social_icons_container {     text-align: center;     align-items: center; display: inline-flex;         margin: 0px !important; } .font_icons { padding: 6px 13px 6px 13px;     cursor: pointer; font-size: 15px;     color: black;     transition: 0.1s all ease-in-out; } .font_icons:hover {     background: black;     color: white; } .share_text {     margin-bottom: 1px;     font-size: 16px;     color: black;     margin-right: 10px; } </style> <div class="social_icons_container"> <p class="share_text">Share<

How to create custom wishlist in wordpress without plugin?

Create custom wishlist in wordpress without plugin. <style> .wishlist-wrapper {     font-size: 12px;     height: 30px;     display: inline-block;     line-height: 30px;     border-radius: 30px;     background: #f1f1f1;     padding: 0px 10px; } span.wishlist-title {     float: left;     margin-right: 5px; } span.little-heart {     float: left;     display: inline-block;     margin-top: 5px; } .wishlist-wrapper:hover {     //background: #ff9900; } .wishlist-wrapper:hover > span.wishlist-title { //color:#fff; } .products .wishlist-title { display:none; } .products .wishlist-wrapper { height:40px; width:40px; border-radius:40px; } .products  span.little-heart {     float: left;     display: inline-block;     margin-top: 11px;     margin-left: 1px; } .added .wishlist-wrapper { background:#ff9900; } .added span.wishlist-title { color:#fff; } .p

How to create OTP login in woocommerce wordpress?

Create OTP login in woocommerce wordpress. Note:  Use console while using this code. Note: You can separate jquery and css. function wooc_extra_register_fields() {?>        <p class="form-row form-row-wide">        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />        </p>            <?php  }  add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );  function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_phone'] ) ) {    $hasPhoneNumber= get_users('meta_valu

How to create login with phone number in woocommerce wordpress?

Create login with phone number in woocommerce wordpress. function wooc_extra_register_fields() {?>        <p class="form-row form-row-wide">        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />        </p>            <?php  }  add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );  function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) { if ( isset( $_POST['billing_phone'] ) ) {    $hasPhoneNumber= get_users('meta_value='.$_POST['billing_phone']);    if ( !empty($hasPhoneNumber)) {      $validation_er

How to customize login process in woocommerce and wordpress ?

Customize login process in woocommerce and wordpress. $customfield = $_POST['phone_number']; $UsermetaData = get_users('meta_value='.$customfield); //print_r($UsermetaData); foreach($UsermetaData as $userdata){ $user = $userdata->ID; } if (!is_wp_error($user)) {     wp_clear_auth_cookie();     wp_set_current_user($user);     wp_set_auth_cookie($user);     $redirect_to = user_admin_url();     wp_safe_redirect( user_admin_url() );     exit(); } return $user;

How to show automatically Login box on checkout page in woocommerce?

If user is not login in woocommerce on checkout page then checkout login option will automatically enable to login. Login with checkout page login option in woocommerce function show_login_option(){  $slug = basename(get_permalink());  if($slug=='checkout'){ if ( is_user_logged_in() ) { // echo '<script>alert("your are login");</script>'; } else {  ?>  <script> jQuery(document).ready(function($) {   $(window).load(function() { $('.showlogin').click(); //alert('hello'); }); });   </script>   <?php } } } add_action('wp_head','show_login_option');

Login with Phone number in Woocommerce WordPress

Login with Phone number in Woocommerce WordPress function wooc_add_phone_number_field() {     return apply_filters( 'woocommerce_forms_field', array(         'wooc_user_phone' => array(             'type'        => 'text',             'label'       => __( 'Phone Number', ' woocommerce' ),             'placeholder' => __( 'Your phone number', 'woocommerce' ),             'required'    => true,         ),     ) ); } add_action( 'woocommerce_register_form', 'wooc_add_field_to_registeration_form', 15 ); function wooc_add_field_to_registeration_form() {     $fields = wooc_add_phone_number_field();     foreach ( $fields as $key => $field_args ) {         woocommerce_form_field( $key, $field_args );     } } add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' ); function wooc_save_extra_register_fields( $cus