I have a website with 50k+ orders, when operators search for an order, they search by name or phone number, after some testing and debugging, I've noticed that one of the reason the search is so slow it's because it searches through the billing/shipping address and I want to remove that.
I've used the following:
function custom_woocommerce_shop_order_search_fields( $search_fields ) {
unset( $search_fields );
$search_fields[] = '_billing_last_name';
$search_fields[] = '_billing_first_name';
$search_fields[] = '_billing_phone';
$search_fields[] = '_billing_email';
return $search_fields;
}
add_filter( 'woocommerce_shop_order_search_fields', 'custom_woocommerce_shop_order_search_fields' );
But doing so, the first and last name skip searches - if I have 5 orders from John Doe, it will sometimes show just 3 or none; As a temporary solution I've disabled this function and came here in hope of enlightenment!
Does anyone have an idea on how to auto replace letters in woocommerce order forms! basically I need when someone is typing in greeklish to auto replace those letters to Greek!
I think you will have to use this hook to get the newly created order :
add_action( 'woocommerce_new_order', 'convert_greeklish_for_wc_order', 1, 1 );
function create_invoice_for_wc_order() {
function create_invoice_for_wc_order( $order_id ) {
// get order details data...
$order = new WC_Order( $order_id );
// Here goes the code to get all the fields
// Convert fields to greek
// Set new fields values
};
}
And adapt this code to convert greeklisk to greek:
<?php
function greeklish($new_text){
$greek_len = array('α','ά','Ά','Α','β','Β','γ', 'Γ', 'δ','Δ','ε','έ','Ε','Έ','ζ','Ζ','η','ή','Η','θ','Θ','ι','ί','ϊ','ΐ','Ι','Ί', 'κ','Κ','λ','Λ','μ','Μ','ν','Ν','ξ','Ξ','ο','ό','Ο','Ό','π','Π','ρ','Ρ','σ','ς', 'Σ','τ','Τ','υ','ύ','Υ','Ύ','φ','Φ','χ','Χ','ψ','Ψ','ω','ώ','Ω','Ώ',' ',"'","'",',');
$english_len = array('a', 'a','A','A','b','B','g','G','d','D','e','e','E','E','z','Z','i','i','I','th','Th', 'i','i','i','i','I','I','k','K','l','L','m','M','n','N','x','X','o','o','O','O','p','P' ,'r','R','s','s','S','t','T','u','u','Y','Y','f','F','ch','Ch','ps','Ps','o','o','O','O',' ','',' ',' ');
$new_text = str_replace($greek_len,$english_len,$new_text);
return $new_text;
}
$conv = greeklish("Το κείμενο σου εδώ!");
echo $conv; #To keimeno sou edo!
?>
Have situation with custom price for item line in WooC.
Now find solution to change subtotal in Edit of order this way:
add_action( 'woocommerce_update_order_item', function ($_item_id, $_item, $_order_id) {
if( $arr_item_meta = wc_get_order_item_meta($_item_id) )
{
$prc = wooc_item1_price( $arr_item_meta["_a1"][0], $arr_item_meta["_a2"][0], $arr_item_meta["_a3"][0], $_item->get_product()->get_id() );
$_item -> set_total( $prc );
$_item -> set_subtotal( $prc );
$_item -> save();
}
},10,3);
This only works on edit. I.e. while updated - it set up price i make with function
wooc_item1_price with few argumens from cart (quantities of each type of product)
Problem is:
howto make same after product just added to cart.
So new subtotal+total will be available in order before any edit/updater.
Please help me!
add_action ('woocommerce_calculate_totals', function( $_cart )
{
foreach ($_cart->cart_contents as $cart_key => $cart_item)
{
$prc = function_to_make_item_custom_price(
$_cart->cart_contents[$cart_key]["_param1"],
$_cart->cart_contents[$cart_key]["_param2"],
$_cart->cart_contents[$cart_key]["_param3"],
$_cart->cart_contents[$cart_key]["product_id"]
);
$_cart->cart_contents[$cart_key]['line_subtotal'] = $prc;
$_cart->cart_contents[$cart_key]['line_total'] = $prc;
}
}, 10,1);
this is right way - make price on adding item to cart.
is need have price function function_to_make_item_custom_price to make custom price, based on parameters. In my case - this is quantites of product parts (tour adult&child&infants param1,param2,param3)
Its simplifed idea, is need also recal taxes, coupons ...
I'd like display a rounded up count of the total number of custom post types.
Currently I am using this
<?php
$count_posts = wp_count_posts('listing');
$published_posts = $count_posts->publish;
echo $published_posts;
?>
but would like to round the number to nearest hundred, so for example,
if the count was 120 it would show 100
if the count was 158 it would show 200
if the count was 1088 it would show 1000
Thanks
This question not related to WordPress, but you will get solution by follow
PHP Custom functions: add into functions.php
if( !function_exists('ceiling') )
{
function ceiling($number, $significance = 1)
{
return ( is_numeric($number) && is_numeric($significance) ) ? (round($number/$significance)*$significance) : false;
}
}
if( !function_exists('ceilNumber') )
{
function ceilNumber($number)
{
return ceiling($number, (int)'1'.str_repeat('0', strlen($number)-1));
}
}
Call above function into your code
$count_posts = wp_count_posts('listing');
$published_posts = $count_posts->publish;
echo ceilNumber($published_posts);
Dear I've a Pizza site and I'm using Woocommerce plugin. I want to apply some price check on attributes.
My Question is
I've a Pizza product which attributes are Size and Meat. Size(Small,large) Meat(Chicken, donair meat etc).
I've applied a check on attributes that when a customer select a product size, small and one piece of meat, the price will be $10 on default rate. But I want to apply this logic here that, when a customer select a more than one piece of meat (Extra topping), Then I want to add $2 on total price like ($10 + $2 = 12).
please help me??
Please use this action for adding the extra price on woocommerce cart.Now you need to work on the commented loop code and apply the simple login.Now I have added a summary for how you will work.
I have use it and now it is working on my local system.
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );
function add_custom_price( $cart_object ) {
$custom_price = 10; // This will be your custome price
foreach ( $cart_object->cart_contents as $key => $value ) {
$productid = $value['product_id'];
$variationArr =$value['variation']; //it is an array have the value : meat and size i.e chicken and small
//In every loop you can count the number of products .
//Note: In array($variationArr),It have all the active attribute of this product which is created by admin in woocommece.
//so you can search it by loop;
/*
* Like
* foreach($variationArr as $k=>$v)
* {
* //here is the variation product size
* }
*
*/
//Now increase the price.
$price = $value['data']->price;
$extraPrice = 2;
$newPrice = $price + $extraPrice;
$value['data']->price = $newPrice;
}
}