As mentioned above I want to display "product added to cart message" in woocommerce.
I know there is some kind of built in function
wc_add_to_cart_message()
If I paste it in index page together with
wc_print_notices();
Like this:
wc_add_to_cart_message('products');
wc_print_notices();
wc_add_to_cart_message('products');
wc_print_notices();
then my current output is:
“” has been added to your cart.
My desired output is that it would return that particular product name together with a message.
but what would be the proper way of using it?
Or is there some other way?
In that function you actually have to give product id or array of product ids, so your line should look like:
wc_add_to_cart_message($product_id);
Related
I am using both WooCommerce (WC) and Modern Events Calendar (MEC). I am trying to display a list view of the MEC events on a corresponding WC product page. As there is no connecting between these two instances it will need some creativity to get to work.
The WC product pages won't be changing a lot in the future so I figured I'd use the product ID. Then every event I make in MEC, I tag with the WC product ID. Then on the frontend I have the MEC shortcode (the list view widget) filter it's output on the WC product ID. Sounds simple enough but I have not been able to figure out how I can get it to work.
In my quest to archive this I have created a shortcode in MEC and changed the filter setting to filter by tag with the following variable [prod_id] after I created this shortcode in the functions file:
function product_id_shortcode() {
global $product;
$id = $product->get_id();
return $id;
}
add_shortcode( 'prod_id', 'product_id_shortcode' );
Unfortunately this did not give the expected result, so I assume filtering by [prod_id] is not being accepted. Any help would be greatly appreciated!
As mentioned above I want to display "product added to cart message" in woocommerce.
I know there is some kind of built in function
wc_add_to_cart_message()
If I paste it in index page together with
wc_print_notices();
Like this:
wc_add_to_cart_message('products');
wc_print_notices();
then my current output is:
“” has been added to your cart.
My desired output is:
that it would return that particular product name together with a message.
but what would be the proper way of using it?
Or is there some other way?
Hi I have a web page with Wordpress and WooCommerce, but the stock (quantity available of each product) I get it in a URL like this (http://www.mystock.com/page.php&id_item=623533&coloritem=68)
I have to put in the link, the SKU (e.g. 623533-68) and I get in return a CVS whit some data
I need to update (or at least show in memory/in front-end) the real price_a and quantity available. How can I do that?
EDIT 1:
For now I don´t need the code for get the CSV info, for information is:
$url = "http://www.mystock.com/page.php&id_item=623533&coloritem=68";
$csv = file_get_contents($url);
$data = str_getcsv($csv);
$data
is an array of string, and I can get the info that I need.
But I still don't know what php file of wordpress to change, for show the actual_quantity and the if the customer add in a cart the product, know if quantity is greater than zero.
EDIT 2:
In this page show the oficial way that update the quantity, whit the function
$product->set_stock_quantity(SomeFloat); but doesn't works. $product is a new WC_Product object. And desn't show any error, just, nothing happen.
Thanks
Is it possible to add a unique name to a specific product when it's added to the shopping cart using the woocommerce API?
For example suppose I sell pets. The user decides he wants a dog named spot. He then clicks on a particular dog breed (the product) say border collie and that product should appear in the shopping cart as a border collie named spot.
To answer your question, yes. You can change things in your own code by adding filters. So for example, say you want to change the name of the product in the cart. In wp-content/plugins/woocommerce/templates/cart/cart.php there is a filter called 'woocommerce_cart_item_name' where the title is outputted. You can modify this in your own code like so:
function your_function( $title, $cart_item, $cart_item_key ){
/*code to modify title*/
return $title;
}
add_filter('woocommerce_cart_item_name','your_function',10,3);
You could add this to the functions.php of your theme.
How you get the name spot in this function depends on your situation.
Read more about filters at https://codex.wordpress.org/Function_Reference/add_filter
I have created custom post type "Product" in Wordpress and I would like to use Products within my contact form. For example, I would like to have a drop down that is a list of all of my Products so users can select a Product name as the message's Subject. I have Contact Form 7 installed. Is there an easy way to do this?
Thanks !
I think the short answer is no. There is not an easy way to do this. The Contact Form 7 plugin uses shortcodes to construct the select lists. What you need to do is run a query on your Posts -> Products and generate your own select list. I suppose what I would do is write my own shortcode function. Then you can include it in your page.
[myProductsShortCode]
Then you can iterate through that result set and generate your own select list.
http://codex.wordpress.org/Shortcode_API
http://codex.wordpress.org/wpdb#query_-_Run_Any_Query_on_the_Database
People seem to be able to add custom information like that, from
function test_generator() {
/* need to produce html like this:
<span class="wpcf7-form-control-wrap menu-645"><select name="menu-645" class="wpcf7-select"><option value="one">one</option><option value="two">two</option></select></span>
so here we go: */
$list = "<span class=\"wpcf7-form-control-wrap menu-test\"><select name=\"menu-test\" class=\"wpcf7-select\"><option value=\"test1\">test-1</option><option value=\"test2\">test-2</option></select></span>";
return $list;
}
wpcf7_add_shortcode('test', 'test_generator');
and then just use [test] in the contactform