NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<?php
/**
* Your code here.
*
*/
function lbmn_child_scripts() {
// Load the parent stylesheet.
wp_enqueue_style( 'lbmn-parent-style', get_template_directory_uri() . '/style.css', false );
}
add_action( 'wp_enqueue_scripts', 'lbmn_child_scripts', 101, 1 );

/**
* change password field strength.
*/


add_filter( 'woocommerce_min_password_strength', 'reduce_min_strength_password_requirement' );
function reduce_min_strength_password_requirement( $strength ) {
// 3 => Strong (default) | 2 => Medium | 1 => Weak | 0 => Very Weak (anything).
return 0;
}

// Second, change the wording of the password hint.
add_filter( 'password_hint', 'smarter_password_hint' );
function smarter_password_hint ( $hint ) {
$hint = 'Hint: longer is stronger, and consider using a sequence of random words (ideally non-English).';
return $hint;
}

/**
* register fields add.
*/

function woocommerce_edit_my_account_page() {
return apply_filters( 'woocommerce_forms_field', array(
'password2' => array(
'type' => 'password',
'label' => __( 'Confirm Password', 'cloudways' ),
'required' => true,
),
'woocommerce_my_account_page' => array(
'type' => 'select',
'label' => __( 'How did you hear about us', 'cloudways' ),
'required' => true,
'options' => array(
'' => __( 'Select an options.', 'cloudways' ),
'BHW' => __( 'BHW', 'cloudways' ),
'Social Media' => __( 'Social Media', 'cloudways' ),
'Google' => __( 'Google', 'cloudways' ),
'Reference' => __( 'Reference', 'cloudways' ),
'Email' => __( 'Email', 'cloudways' ),
'SMS' => __( 'SMS', 'cloudways' ),
'Other Media' => __( 'Other Media', 'cloudways' ),
),
),
'newsletter' => array(
'type' => 'checkbox',
'label' => __( 'Subscribe to receive email updates on new products, coupons and more.', 'cloudways' ),
'required' => false,
),
) );
}
function edit_my_account_page_woocommerce() {
$fields = woocommerce_edit_my_account_page();
foreach ( $fields as $key => $field_args ) {
woocommerce_form_field( $key, $field_args );
}
}
add_action( 'woocommerce_register_form', 'edit_my_account_page_woocommerce', 15 );


/**
* register fields Validating.
*/
function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
if (($_POST['password'] !== $_POST['password2']) || (empty($_POST['password2']))) {
$validation_errors->add( 'password2_error', __( ' Confirm Password must be same as password!', 'woocommerce' ) );
}
if ((isset($_POST['woocommerce_my_account_page'])) && (empty($_POST['woocommerce_my_account_page']))) {
$validation_errors->add( 'woocommerce_my_account_page_error', __( 'Here about us field is required!', 'woocommerce' ) );
}
return $validation_errors;
}
add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );


/**
* Below code save extra fields.
*/
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['woocommerce_my_account_page'] ) ) {
// Phone input filed which is used in WooCommerce
$up = update_user_meta( $customer_id, '_how_to know', $_POST['woocommerce_my_account_page'] );

$up1 = update_user_meta( $customer_id, '_subscription', $_POST['newsletter'] );
if($_POST['newsletter'] == 1)
{
global $wpdb;
$upd = $wpdb->insert('wp_newsletter', array('name' => $_POST['username'], 'email' => $_POST['email'],'status' =>'C') );
}

}
}
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

/*This is for send customer mail for order cancel*/

add_action('woocommerce_order_status_changed', 'send_custom_email_notifications', 10, 4 );
function send_custom_email_notifications( $order_id, $old_status, $new_status, $order ){
if ( $new_status == 'cancelled' || $new_status == 'failed' ){
$wc_emails = WC()->mailer()->get_emails(); // Get all WC_emails objects instances
$customer_email = $order->get_billing_email(); // The customer email
}

if ( $new_status == 'cancelled' ) {
// change the recipient of this instance
$wc_emails['WC_Email_Cancelled_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_Cancelled_Order']->trigger( $order_id );
}
elseif ( $new_status == 'failed' ) {
// change the recipient of this instance
$wc_emails['WC_Email_Failed_Order']->recipient = $customer_email;
// Sending the email from this instance
$wc_emails['WC_Email_Failed_Order']->trigger( $order_id );
}
}


// Woocommerce New Customer Admin Notification Email
add_action('woocommerce_created_customer', 'admin_email_on_registration');
function admin_email_on_registration() {
global $wpdb;
$query = "SELECT * FROM wp_users ORDER BY user_registered DESC LIMIT 1";
$user_data = $wpdb->get_results($query);
$user_id = $user_data[0]->ID; // last user id from the list
$meta_query = "SELECT * FROM wp_usermeta WHERE user_id = '.$user_id.' AND meta_key = '_how_to know'";
$usermeta_data = $wpdb->get_results($meta_query);
//wp_new_user_notification( $user_id );
$to = '[email protected]';
$email = $user_data[0]->user_email;
$username = $user_data[0]->display_name;
$how_to_know = $usermeta_data[0]->meta_value;
$subject = 'New User Registered';
$body = '<p>Username: <span>'.$username.'</span></p><p>Email: <span>'.$email.'</span></p><p>Marketing Channel: <span>'.$how_to_know.'</span></p><p>Thank You,</p><p>AccountsDaddy</p>';
$headers = array('Content-Type: text/html; charset=UTF-8','From: AccountsDaddy <[email protected]>');
wp_mail( $to, $subject, $body, $headers );

}


// Order cancel btn for user

add_filter( 'woocommerce_valid_order_statuses_for_cancel', 'custom_valid_order_statuses_for_cancel', 10, 2 );
function custom_valid_order_statuses_for_cancel( $statuses, $order = '' ){

// Set HERE the order statuses where you want the cancel button to appear
$custom_statuses = array( 'pending','on-hold');

// Set HERE the delay (in days)
$duration = 3; // 3 days

// UPDATE: Get the order ID and the WC_Order object
if( isset($_GET['order_id']))
{
$order = wc_get_order( absint( $_GET['order_id'] ) );
}

$delay = $duration*24*60*60; // (duration in seconds)
$date_created_time = strtotime($order->get_date_created()); // Creation date time stamp
$date_modified_time = strtotime($order->get_date_modified()); // Modified date time stamp
$now = strtotime("now"); // Now time stamp


// Using Creation date time stamp
if ( ( $date_created_time + $delay ) >= $now ) return $custom_statuses;
else return $custom_statuses;
}

/*add_action('wp_logout','auto_redirect_after_logout');
function auto_redirect_after_logout(){
wp_redirect( site_url('/my-account') );
exit();
}*/

//checkout button on product page.
function add_content_after_addtocart() {

// get the current post/product ID
$current_product_id = get_the_ID();

// get the product based on the ID
$product = wc_get_product( $current_product_id );

// get the "Checkout Page" URL
$checkout_url = wc_get_checkout_url();

//// if cart value is more than zero only shows
if ( WC()->cart->get_cart_contents_count() == 0 )
{}

else
{
if( $product->is_type( 'simple' ) )

{
echo '<a href="'.$checkout_url.'" id="hidefunction" class="newclass single_add_to_cart_button button alt">Checkout</a>';
}

}}

//product page checkout button
add_action( 'woocommerce_after_add_to_cart_button', 'add_content_after_addtocart' );

//shop items



//add_action( 'woocommerce_after_shop_loop_item', 'add_content_after_addtocart' );



//quantity


/**
* Override loop template and show quantities next to add to cart buttons
*/
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
$html .= '<input type="number" id="cus-qty-'.$product->get_id().'" class="input-text qty text" step="1" min="50" max="" name="quantity" value="50" title="Qty" size="4" placeholder="" inputmode="numeric">';
$html .= '<button type="submit" class="button alt">' . esc_html( $product->add_to_cart_text() ) . '</button>';
$html .= '</form>';
}
return $html;
}



//clear cart button on cart page

add_action('init', 'woocommerce_clear_cart_url');
function woocommerce_clear_cart_url() {
global $woocommerce;
if( isset($_REQUEST['clear-cart']) ) {
$woocommerce->cart->empty_cart();
}
}

//coupon field
remove_action( 'woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10 );

//continue shopping page at cart page.

add_action( 'woocommerce_after_cart', 'tl_continue_shopping_button' );
function tl_continue_shopping_button() {
$shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );

echo '<div class="left">';
echo ' <a href="'.$shop_page_url.'" class="checkout-button button alt wc-forward">Continue Shopping →</a>';
echo '</div>';
}
//reorder button on order pages


/**
* Add order again button in my orders actions.
*
* @param array $actions
* @param WC_Order $order
* @return array
*/
function cs_add_order_again_to_my_orders_actions( $actions, $order ) {
if ( $order->has_status( 'completed' ) ) {
$actions['order-again'] = array(
'url' => wp_nonce_url( add_query_arg( 'order_again', $order->get_id() ) , 'woocommerce-order_again' ),
'name' => __( 'Order Again', 'woocommerce' )
);
}

return $actions;
}

add_filter( 'woocommerce_my_account_my_orders_actions', 'cs_add_order_again_to_my_orders_actions', 50, 2 );

//delete items from cart

/**
* Gets Variation ID if available otherwise it will get the Product ID
* @param $product Product
* @param bool $check_variations Whether or not to check for variation IDs
* @return mixed
*/
function get_id_from_product( $product, $check_variations = false ) {
if( $check_variations ) {
return ( isset( $product['variation_id'] )
&& ! empty( $product['variation_id'])
&& $product['variation_id'] != 0 )
? $product['variation_id']
: $product['product_id'];
} else {
// No variations, just need the product IDs
return $product['product_id'];
}
}

/**
* Checks the existence of a specific product in the cart
* @param $product_required The Product ID required to be in the cart
* @return bool
*/
function qualifies_basedon_specific_product( $product_required ) {
if( is_cart() || is_checkout () ) {
foreach( WC()->cart->cart_contents as $key => $product_in_cart ) {
if( $product_required == get_id_from_product( $product_in_cart ) ) {
return true;
}
}
return false;
}
}

/**
* Checks for quantity of products in cart
* @param $product
* @param $quantity
* @return bool
*/
function get_product_quantity( $product, $quantity ) {

if( is_cart() || is_checkout() ) {
if( qualifies_basedon_specific_product( $product ) ) {
foreach( WC()->cart->cart_contents as $item => $values ) {
if( $product == $values['product_id'] && $quantity == $values['quantity'] ) {
return true;
}
}
}
return false;
}
}

/**
* Checks the cart for the Total excluding taxes
* @param $total_required
* @return bool
*/
function qualifies_basedon_cart_total( $total_required ) {
if( is_cart() || is_checkout () ) {
if( WC()->cart->subtotal_ex_tax >= $total_required ) {
return true;
}
}
return false;
}

/**
* Adds a specific product to the cart. Accepts a quantity and price override
* @param $product_id Product to be added to the cart
* @param $quantity Add X of counts of $product_id
* @param $price Set price of $product_id before adding
* @return bool
*/
function add_product_to_cart( $product_id, $quantity, $price ) {
$cart_id = WC()->cart->generate_cart_id( $product_id );
$prod_in_cart = WC()->cart->find_product_in_cart( $cart_id );
// Add the product only if it's not in the cart already
if( ! $prod_in_cart ) {
WC()->cart->add_to_cart( $product_id, $quantity );
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
if( $cart_item['data']->id == $product_id ){
$cart_item['data']->set_price( $price );
}
}
}
}

/**
* Removes a specific product from the cart
* @param $product_id Product ID to be removed from the cart
*/
function remove_product_from_cart( $product_id ) {
$prod_unique_id = WC()->cart->generate_cart_id( $product_id );
// Remove it from the cart by un-setting it
unset( WC()->cart->cart_contents[$prod_unique_id] );
}

add_action( 'woocommerce_check_cart_items', 'qualifies_for_incentive' );
add_action( 'woocommerce_before_cart', 'qualifies_for_incentive');
function qualifies_for_incentive() {
$incentive_product_id = 652;
if( qualifies_basedon_specific_product( 79 ) && qualifies_basedon_cart_total( 895 ) ) {
if( get_product_quantity( 79, 3 ) ) {
add_product_to_cart( $incentive_product_id, 3, 1 );
}
} else {
remove_product_from_cart( $incentive_product_id );
}
}

add_filter( 'woocommerce_quantity_input_args', 'bloomer_woocommerce_quantity_changes', 10, 2 );
function bloomer_woocommerce_quantity_changes( $args, $product ) {
//$product->id
if ( ! is_cart() ) {
$args['input_value'] = 50; // Start from this value (default = 1)
$args['max_value'] = -1; // Max quantity (default = -1)
$args['min_value'] = 50; // Min quantity (default = 0)
$args['step'] = 1; // Increment/decrement by this value (default = 1)
} else {
// Cart's "min_value" is already 0 and we don't need "input_value"
$args['max_value'] = -1; // Max quantity (default = -1)
$args['min_value'] = 50; // Min quantity (default = 0)
$args['step'] = 1; // Increment/decrement by this value (default = 0)
// COMMENT OUT FOLLOWING IF STEP < MIN_VALUE
}
return $args;
}


function wpb_cookies_tutorial1() {

$visit_time = date('F j, Y g:i a');

if(!isset($_COOKIE[$wpb_visit_time])) {

// set a cookie for 1 year
setcookie('wpb_visit_time', $current_time, time()+31556926);

}

}

function wpb_cookies_tutorial2() {
// Time of user's visit
$visit_time = date('F j, Y g:i a');

// Check if cookie is already set
if(isset($_COOKIE['wpb_visit_time'])) {

// Do this if cookie is set
function visitor_greeting() {

// Use information stored in the cookie
$lastvisit = $_COOKIE['wpb_visit_time'];

$string .= 'You last visited our website '. $lastvisit .'. Check out whats new';

return $string;
}

} else {

// Do this if the cookie doesn't exist
function visitor_greeting() {
$string .= 'New here? Check out these resources...' ;
return $string;
}

// Set the cookie
setcookie('wpb_visit_time', $visit_time, time()+31556926);
}

// Add a shortcode
add_shortcode('greet_me', 'visitor_greeting');

}
add_action('init', 'wpb_cookies_tutorial2');

// Defer Parsing of JavaScript in WordPress via functions.php file
// Learn more at https://technumero.com/defer-parsing-of-javascript/

function defer_parsing_js($url) {
//Add the files to exclude from defer. Add jquery.js by default
$exclude_files = array('jquery.js');
//Bypass JS defer for logged in users
if (!is_user_logged_in()) {
if (false === strpos($url, '.js')) {
return $url;
}

foreach ($exclude_files as $file) {
if (strpos($url, $file)) {
return $url;
}
}
} else {
return $url;
}
return "$url' defer='defer";

}
add_filter('clean_url', 'defer_parsing_js', 11, 1);

add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '61288' == event.detail.contactFormId) {
location = 'https://accountsdaddy.com/thank-you-for-contact-us/';
}
if ( '61290' == event.detail.contactFormId) {
location = 'https://accountsdaddy.com/thank-you/';
}
}, false );
</script>
<?php
}
/**
* Filters the log out redirect URL.
*
* @since 4.2.0
*
* @param string $redirect_to The redirect destination URL.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User $user The WP_User object for the user that's logging out.
*/
add_filter( 'logout_redirect', function( $redirect_to, $requested_redirect_to, $user ) {
if ( ! $requested_redirect_to ) { // Don't override the redirect if one was already set in the logout URL
$redirect = home_url( user_trailingslashit( 'my-account' ) );
}

return $redirect;
}, 10, 3 );
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.