I am working on a website where I am using woocommerce but rather than have a shopping facility I'm trying to change the wording, whilst keeping all the functionality to be able to add products to the shopping cart but calling everything an enquiry, and call for quote in replace for prices.
I have set prices so that when 0 is entered it won't display the standard 'Free!' and instead it states 'Call for quote' by adding this to my functions.php
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woo_custom_cart_button_text' ); // 2.1 +
function woo_custom_cart_button_text() {
return __( 'Add to Enquiry', 'woocommerce' );
}
This works fine, and i sourced this particular hook online to obtain the code, however now I am starting to get further into the project I am wanting to edit more than just button texts.
My question is, how do you know where to obtain the hook names so I can start to create my own hooks for this, can they be seen from the class names when inspecting on google devtools? Dragging the woocommerce folder over into Sublime Text 2 and conducting a search for woocommerce_product_single_add_to_cart_text I can be returned with reults to be able to see that hook, but how do you come across the hook name to begin with?
I have looked at http://docs.woothemes.com/wc-apidocs/hook-docs.html but couldn't see any names in relation to the above hook to begin trying to decipher how or where it was obtained.
how do you know where to obtain the hook names so I can start to
create my own hooks for this, can they be seen from the class names
when inspecting on google devtools?
No.
To find a particular hook, you'd need to look at the code base. In repositories that are well organised such as WooCommerce, you should generally have a rough idea where to look for a particular hook.
For example, if I wanted hook in to the thankyou page I would probably first try looking in templates > checkout > thankyou.php. There I would find the woocommerce_thankyou action hook which would let me insert my custom functionality.
Alternatively, there's the WooCommerce hook documentation.
Related
I would like to modify the behavior of upsells and cross-sells product search in the admin product edit. It should search only in product titles.
By default, it searches description as well. That’s why there are too many score, I can’t find the product what I search.
[1
I had the same problem with the frontend product finder, but I solved it with a hook. Is there any hook for upsell and cross-sell finder?
Thanks!
The search request goes to this function
https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/data-stores/class-wc-product-data-store-cpt.php#L1582
There you can find a filter woocommerce_product_pre_search_products for a custom result, so basically you'll have to copy-paste the whole code below that filter line and remove a few things from line no 1651 or you can just modify the core plugin files.
However, I don't see any specific param to identify the request so this change will affect everywhere on the website where search_products is used from the data store.
I am trying to validate the content of a cart before allowing the order to be placed. This seems to be a trivial task using common hooks like woocommerce_checkout_process action hook, which works fine in most of the cases.
In the website I am working on, it seems there is some complex cases where other plugins are editing the content of the cart thus the above hook isn't enough.
I want to know what is the last hook called before the order is created in the database and before any payment is done. I want to make sure I run my validation after any potential changes to avoid non-needed orders.
I have looked around here: https://woocommerce.github.io/code-reference/hooks/hooks.html searching with the keyword order but there is a ton of results.
I have identified (I guess) the create() function which contain the hook woocommerce_new_order_item but this one is called after the creation not before.
Which hook will make sure there is no changes done between my validation and the creation of orders?
Last hook before order creation is woocommerce_checkout_create_order located in WC_Checkout method create_order() As you can see the order is created just after this hook with the code line:
$order->save();
For order items (the following hooks are also located in WC_Checkout method create_order(), before order creation):
"line" items use woocommerce_checkout_create_order_line_item filter hook.
"fee" items use woocommerce_checkout_create_order_fee_item filter hook.
"shipping" items use woocommerce_checkout_create_order_shipping_item filter hook.
"tax" items use woocommerce_checkout_create_order_tax_item filter hook.
"coupon" items use woocommerce_checkout_create_order_coupon_item filter hook.
Now for fields validation, you can use 2 different hooks located in WC_Checkout class:
woocommerce_after_checkout_validation (some examples with this hook)
woocommerce_checkout_process (some examples with this hook)
Hope someone can point me in the right direction, we have a custom plugin for wooommerce, developer left us!!!
The custom plugin is a custom post type, actually a bundle with many custom weights making up the product, to keep it simple think of it has a cake with ingredients.
The owner now wants the product (custom product type) to have 3 variations.
This will never change always 3 no more no less.
I can find tuitions on creating custom product types, but nothing is out there calling variations into a custom product type.
I need to get the basic workings correct so as i approach other developers i can gauge what is going on.
I know i am being vague but i cannot post the plugin on here.
I keep seeing reference to the Class: WC_Product_Variable
Do i need the plugin to add a function for variables to be switched on as such, with a call to a variable function file.
Also calling an add to cart variable file.
Can some of the code be used from the woocommerce file class-wc-product-variation.php
help and guidance aprreciated
As the title says, I want to remove the invoice fee from the customer-processing-order.php (I Think this is the right template)
https://github.com/woothemes/woocommerce/blob/master/templates/emails/customer-processing-order.php
From what I understand it comes from the function get_order_item_totals().
I can't just use CSS to hide it either because everything is inside a table. I found a website where someone was trying to hide the shipping cost and he used this:unset($totals['shipping']); inside the php file, which seemed pretty straightforward and clean. I wish you could just write something like unset($totals['invoice']); but unfortunately that's not the case.
Anyone got any ideas? I can't turn it off anywhere inside Woocommerce either.
do you have a screenshot of what exactly you want to be removed? I don't have an "invoice fee" anywhere at checkout ...
For specific product needs, I am creating a custom api for my application to query WooCommerce.
I am able to hook into the 'parse_request' action, but it would seem that this is too early for woocommerce to be correctly setup.
I know this because if I try to query for order information, I am getting back error objects saying that taxonomie is incorrect.
What do I need to do to correctly have woocommerce initialised so that I can query for orders and products (along with their custom attributes) ?
Can anyone help me with this ?
I'm not sure I fully understand what you are trying to do so I will attempt to cover both possibilities.
The WooCommerce API can be accessed via https://www.example.com/wc-api/v1/.
Alternatively, WooCommerce is fully loaded by the time plugins_loaded is fired (aka when all plugins are done loading). To do something specifically when WooCommerce is loaded you can use woocommerce_loaded. But parse_request comes after plugins_loaded and even comes after init which is where WooCommerce is loading its taxonomies. Are you sure you are using the correct taxonomy names? For example, Attribute taxonomies are preceded by pa_ so a Color attribute would have a taxonomy of pa_color.
If you adjust your question to clarify what you are doing I might be able to help further.