Where i can edit this price element woocommerce? - wordpress

I want to replace the word "De: " of all products, but I do not know where
Link to website

You can change the "From" text via the woocommerce_get_price_html_from_text filter.
You would do so, like this:
add_filter( 'woocommerce_get_price_html_from_text', 'so_43054760_price_html_from_text' );
function so_43054760_price_html_from_text( $text ){
return __( 'whatever', 'your-plugin-textdomain' );
}
Keep in mind this is WooCommerce 3.0-specific code. I'm not sure it is back-compatible with WC 2.6.x.

Related

Woocommerce breadcrumbs

I want to change the default Woocommerce breadcrumbs on the tag archives. Currently they are "Home / Products tagged with "..." ", and I just want "Home / Tag name".
I could not find anything on how to achieve this, the Woo docs just explain how to change the delimiter or change the word "Home".
You can see it at wp-content\plugins\woocommerce\includes\class-wc-breadcrumb.php with
private function add_crumbs_product_tag()
{
$current_term = $GLOBALS['wp_query']->get_queried_object();
$this->prepend_shop_page();
/* translators: %s: product tag */
$this->add_crumb( sprintf( __( 'Products tagged “%s”', 'woocommerce' ), $current_term->name ) );
}
just change 'Products tagged “%s”' to '%s' if you permanently remove product tagged.... Make sure you are changing private function of woocommerce.

How to change the message in woocommerce order table

This is my first post here and I am really hoping that someone will be able to assist..
I am using woocommerce 2.6 and when the product is in stock (for example invetory of 2) and I make the backorder choice “Allow, but notify customer”, then on the product page I can see 'in stock'.
Then, the notifications displayed in the cart, checkout and subsequent customer emails is showing 'Back ordered: 4'
screenshot
Could you please tell me how I can change the message 'Back ordered: 4' to 'Low Stock'?
I tried to search for the string 'Back ordered' using grep -r "Back ordered" but couldn't find it anywherestrong text
Could anyone please help?
Thank you
Fred
I think you'll find it in /includes/abstracts/abstract-wc-order.php
wc_add_order_item_meta( $item_id, apply_filters('woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ) ), $qty - max( 0, $product->get_total_stock() ) );
And you can also change it in the language file, it is the proper way to do it.
This message is located here :
wp-content/plugins/woocommerce/includes/wc-formatting-functions.php
$display .= ' ' ;// . __( '(can be backordered)', 'woocommerce' );

how to add text area and checkbox before order details on Woocommerce checkout page

I want to add some one check box, one text area and one link before the order details on checkout. I tried to find all over the stackoverflow but I did not found any exact information or code. If anyone help me so I will be very thankful to you. check screen shot for more info http://prntscr.com/9dtloy
add_action( 'woocommerce_review_order_before_payment', 'skyverge_before_paying_notice' );
function skyverge_before_paying_notice() {
wc_print_notice( __( 'Here is some text', 'woocommerce' ), 'error' );
}
I tried this code which is showing something like this http://prntscr.com/9dttsi
Thanks
Have you tried add_action( 'woocommerce_review_order_before_order_total', 'my_custom_fields' );
function my_custom_fields(){
// put your custom fields out here
}
The following hook will add the text before the order details but below the "Your order" text.
//Hook
add_action('woocommerce_before_cart_contents', 'fields_before_order_details');
//function
function fields_before_order_details(){
wc_print_notice( __( 'Here is some text', 'woocommerce' ), 'error' );
}
This is not the only hook that will achieve this, you can find a list of more Woocommerce hooks here.
This is how we can show content right before the "Your Order"
add_action('woocommerce_after_checkout_billing_form', 'fields_before_order_details');
//function
function fields_before_order_details(){
echo 'Terms & Conditions';
}
Thanks all for your contribution

Limit shipping to specific State's only

I want to limit shipping to my customer to specific states only. Actually i want to show specific states on my shipping address state field. I have try this
function patricks_only_ship_to_continental_us( $available_methods ) {
global $woocommerce;
$excluded_states = array( 'AK','HI','GU','PR' );
if( !in_array( $woocommerce->customer->get_shipping_state(), $excluded_states ) ) {
// Empty the $available_methods array
$available_methods = array();
}
return $available_methods;
}
add_filter( 'woocommerce_package_rates', 'patricks_only_ship_to_continental_us', 10 );
but this seems to be not working as a expected, Its throws error message while placing the order. I don't want my customer select invalid shipping method.
I have also tried these filter but they change both shipping and billing address state field
woocommerce_states
woocommerce_countries_allowed_country_states
Here is example of enable shipping to limited state of india only.
place below code into your function.php
add_filter( 'woocommerce_states', 'custom_woocommerce_states' );
function custom_woocommerce_states( $states ) {
$states['IN'] = array(
'GA' => __( 'Goa', 'woocommerce' ),
'JK' => __( 'Jammu and Kashmir', 'woocommerce' ),
'JH' => __( 'Jharkhand', 'woocommerce' ),
'GJ' => __( 'Gujarat', 'woocommerce' )
);
return $states;
}
Modify array list by listing of state where you want to enable shipping.
You can get list of state code from woo commerce default state
plugins\woocommerce\i18n\states
I cannot comment so I'll post as an answer, There are a lot of plugins that can do this by adding something like a search bar where you're customer can enter there zip code and check if you are delivering in that place. It can also restrict them to add anything in a cart if they haven't checked their zip code yet.
Here's the list of plugin's I know so far. Everything's paid though
http://gremlin.io/shop/woocommerce-plugins/restrict-check-cod-payment-method-zip-pin-codes-woocommerce
http://codecanyon.net/item/zip-code-checker/8740060
http://codecanyon.net/item/wp-triggers-add-instant-interactivity-to-wp/3516401?sso%3FWT.ac=search_item&ref=cmoreira&WT.seg_1=search_item&WT.z_author=deptweb730&ref=cmoreira&clickthrough_id=410306377&redirect_back=true

Woocommerce - Product price depending on country

I have 2 questions regarding Woocommerce for Wordpress.
I'm working on a site that sells speakers to the Danish market.
Question one:
Can I detect the IP of a visitor and detect which country the person is from? I guess this can be done with some ClientLocation api.
Can I then disable all shopping relatet pages and buttons if a person is not from Denmark. Fx: hiding the add to cart, cart and checkout.
I still want the persons to be able to see the prices, they should just not have the option to buy them.
Question 2:
Lets say that question one was sucessfull made. Then I would like to show different prices for other contries than Denmark. So if you are visiting the site from one country, the price is XXX and from another country the price is XXXX.
Let's say:
In USA the price is = $500
And in UK the price = £400
(This has nothing to do with currency. The market price is just different in different countries.)
I've looked at this plugin: http://wordpress.org/plugins/woocomerce-price-by-country/
It allowed me to write different prices for each product, but when I testet it with http://geopeeker.com/ I hadn't worked at all.
Can you give me some pointets or some links to some plugins that you know of?
UPDATE
I managed to solve question 1. I store the visitors country in a cookie with IP location XML API And then I could just create an if statement, saying that if the country was not equal to Denmark, then the add to cart, cart etc. should be removed.
So yeah, I would really appreciate it if anyknow could give me an idea on how I can solve question 2.
I'm able to detect country, but not able to specify a price of each product to the given country.
2'nd update:
Just to let any interested readers know, I ended up buying this plugin. which is working perfectly!
For the 2nd part of your question: If you are only using simple product types (without variations) then you can add custom price fields to the product data page and filter the price using woocommerce_get_price_html.
add_filter('woocommerce_get_price_html','so24863612_custom_price');
function so24863612_custom_price(){
global $post;
$_postID = $post->ID;
$product = get_product( $_postID );
$UK_price = get_post_meta($_postID, '_UK_price', true); //loads custom meta data
$return_price = $product->get_regular_price(); //default to regular price
if (!empty($UK_price)) {
$return_price = $UK_price;
}
return $return_price;
}
You can create and save custom fields on the product page like this:
//Display custom fields on product data page in admin
add_action( 'woocommerce_product_options_general_product_data', 'so24963039_display_custom_general_tab_fields' );
function so24963039_display_custom_general_tab_fields() {
global $woocommerce, $post;
$UK_price = get_post_meta( $post->ID, '_UK_price', true );
woocommerce_wp_text_input(
array(
'id' => '_UK_price',
'label' => __( 'UK Price (£)', 'woocommerce' ),
'value' => $UK_price,
'desc_tip' => 'false'
)
);
}
//Save custom fields to access via get_post_meta
add_action( 'woocommerce_process_product_meta', 'so24963039_save_custom_general_tab_fields' );
function so24963039_save_custom_general_tab_fields ($post_id) {
$woocommerce_UK_price = $_POST['_UK_price'];
if( !empty( $woocommerce_UK_price ) )
update_post_meta( $post_id, '_UK_price', esc_attr( $woocommerce_UK_price ) );
}
-----------------For products with Variations----------------------------
WARNING: Variable products are much more complicated and I'm not nearly as confident in this answer as I am with the simple products part above, but here's my current understanding either way. I had some mini-cart display issues that I had to hack around when using this method (which I will explain at the end), but the totals are calculated correctly in both the mini-cart and the regular cart.
First we want to add new fields to each variant on the variation tab of existing products:
add_action( 'woocommerce_product_after_variable_attributes', 'so24963039_variable_fields', 10, 2 ); //Display Fields
function so24963039_variable_fields( $loop, $variation_data ) {
echo '<tr><td>';
woocommerce_wp_text_input(
array(
'id' => '_variant_UK_price['.$loop.']',
'label' => __( 'UK Price (£)', 'woocommerce' ),
'desc_tip' => 'false',
'value' => $variation_data['_variant_UK_price'][0]
)
);
echo '</td></tr>';
}
We also need to add them dynamically whenever the user adds new variants on the edit product page:
add_action( 'woocommerce_product_after_variable_attributes_js', 'so24963039_variable_fields_js' ); //JS to add fields for dynamically added new variations
function so24963039_variable_fields_js(){ //add fields to new variations that get added
echo '<tr><td>';
woocommerce_wp_text_input(
array(
'id' => '_variant_UK_price[ + loop + ]',
'label' => __( 'UK Price (£)', 'woocommerce' ),
'desc_tip' => 'false',
'value' => $variation_data['_variant_UK_price'][0]
)
);
echo '</td></tr>';
}
Then we save changes to the custom fields in the variation meta data:
add_action( 'woocommerce_process_product_meta_variable', 'so24963039_save_variable_fields', 10, 1 ); //Save variation fields
function so24963039_save_variable_fields( $post_id ) {
if (isset( $_POST['variable_sku'] ) ) {
$variable_sku = $_POST['variable_sku'];
$variable_post_id = $_POST['variable_post_id'];
// Variant Tier 1 Price
$_variant_UK_price = $_POST['_variant_UK_price'];
for ( $i = 0; $i < sizeof( $variable_sku ); $i++) {
$variation_id = (int) $variable_post_id[$i];
if ( isset( $_variant_UK_price[$i] ) ) {
update_post_meta( $variation_id, '_variant_UK_price', stripslashes($_variant_UK_price[$i] ) );
}
}
}
}
Now that we have our custom variation meta data, we can access it in the custom price module like so:
add_filter('woocommerce_get_price_html','so24863612_custom_price');
function so24863612_custom_price(){
global $post;
$_postID = $post->ID;
$product = get_product( $_postID );
$product_type = $product->product_type;
$UK_price = get_post_meta($_postID, '_UK_price', true); //covers simple products
if($product_type == 'variation'){ //override with variant prices
$UK_price = get_post_meta($_postID, '_variant_$UK_price', true);
}
$return_price = $product->get_regular_price(); //default to regular price
if (!empty($UK_price)) {
$return_price = $UK_price;
}
return $return_price;
}
Now, I believe that part should have everything working except for the mini-cart display. For some reason it seems like I just couldn't figure out how to get access to the variation meta data to force it to display properly in the mini cart - like I found where the mini-cart display was being generated but I was having trouble getting the right context path to access the custom variable so I ended up having to do that in the template-tags.php and pass an array of custom values to an optional parameter in my custom price function. This feels very 'wrong' in terms of how we should do things, but it gets the job done. I'm very open to hearing the 'correct' solution to this part of the problem.
In template-tags.php:
<div class="small-7 large-7 columns"><?php
$product_title = $_product->get_title();
echo '<a class="cart_list_product_title" href="'.get_permalink($cart_item['product_id']).'">' . apply_filters('woocommerce_cart_widget_product_title', $product_title, $_product) . '</a>';
echo '<div class="cart_list_product_price">';
//original line: echo woocommerce_price($_product->get_price());
/*Custom Price Override Block*/
$_productID = $_product->id;
$product_type = $_product->product_type;
if($product_type == 'variation') {
$custom_field_data = $_product->product_custom_fields;
$regular_price = $custom_field_data['_regular_price'];
$custom_UK_price = $custom_field_data['_variant_UK_price'];
$custom_variant_prices = [$regular_price[0], $custom_UK_price[0]];
echo so24863612_get_custom_price($_productID, $custom_variant_prices );
} else {
echo so24863612_get_custom_price($_productID );
}
/*End Custom Price Override Block*/
echo ' /</div>';
echo '<div class="cart_list_product_quantity">'.__('Quantity', 'woocommerce').': '.$cart_item['quantity'].'</div>';
?></div>
I see your update that you did manage to get the visitor's country and that you can use this to create the if statement to remove the cart. (which is freaking cool, by the way)
Doesn't that answer your question 2, about changing the prices for each visitor? All you have to do is make sure that both prices are stored somewhere, and then just have it echo the Denmark or the UK one.
Prices are specific - custom fields
You mentioned this is NOT currency conversion - so you need to store both values. Add a custom field to the product entry that you edit with that new price, and name it "denmarkprice" or something
I'm not 100% familiar enough with WooCommerce to say what custom field plugin might work, but you could use http://www.advancedcustomfields.com/ if you don't want to just create the custom field yourself and call the variable with the_meta() when you want to display it inside your if else statement.
http://codex.wordpress.org/Custom_Fields

Resources