Dan
(@danbisongriduk)
Yes, this is an issue with the plugin.
Here’s a custom function that I created and put into my functions.php and it works for me!
function wc_sample_stock( $qty, $order, $item ) {
$product_type = woocommerce_get_order_item_meta( $item->get_product_id(), ‘product type’);
foreach ($item->get_formatted_meta_data() as $key => $value) {
if ( $value->key === ‘product type’ ) {
$product_type = $value->value;
break;
}
}
if ( $product_type === ‘sample’ ) {
return 0;
}
return $qty;
}
add_filter( ‘woocommerce_order_item_quantity’, ‘wc_sample_stock’, 3, 3 );
Oh that’s soooo kind of you !
Many thanks !!
Going to implement that right now !
Well… when trying to add that code to functions.pho or woocommerce-sample.php that instantaneously crashes my site, something may be missing ?
Dan
(@danbisongriduk)
is your code formatted correctly like the below?
function wc_sample_stock( $qty, $order, $item ) {
$product_type = woocommerce_get_order_item_meta( $item->get_product_id(), 'product type');
foreach ($item->get_formatted_meta_data() as $key => $value) {
if ( $value->key === 'product type' ) {
$product_type = $value->value;
break;
}
}
if ( $product_type === 'sample' ) {
return 0;
}
return $qty;
}
add_filter( 'woocommerce_order_item_quantity', 'wc_sample_stock', 3, 3 );
Ohhhh Thanks a lot !!!
Of course, quotes were badly encoded, thanks a lot ! π
Works perfectly !
I have the same issue and tried implementing your code, but I’m not sure at which in the .php I should put it.
Could someone advice me, which line would be suitable?
I added it at the beginning of fundctions.php in my theme’s directory.
Looks like this :
<?php
/**
* Road Themes functions and definitions
*/
/**
* Fix Deactivate stock management for samples
* ----------------
*/
function wc_sample_stock( $qty, $order, $item ) {
$product_type = woocommerce_get_order_item_meta( $item->get_product_id(), 'product type');
bla bla bla
Dan
(@danbisongriduk)
@cvetter If in doubt place the code at the end of your functions.php file
@delacourcorp Great! I am glad to have helped π
-
This reply was modified 7 years, 3 months ago by
Dan.
-
This reply was modified 7 years, 3 months ago by
Dan.
Well, I’m still having issues… I implemented the code in my funtions.php of the Unicon theme I’m using and it doesn’t work. Still deducting 1 of the stock.
I tried implementing it in the functions.php of the plugin and it doesn’t work either.
I’m not very firm with coding, but I have an idea, what could be wrong.
In your code you are using three times = and in most other functions in the plugin they only use two times =
Could that be an issue?
Dan
(@danbisongriduk)
@cvetter place the code at the end of your theme’s functions.php file. Also make sure that you are using a child theme if you are using a theme that you did not create, this is to avoid your changes being overwritten when updating your theme. Please also double-check in WordPress that your site has that child theme selected/applied.
== equals in PHP results in “TRUE if $a is equal to $b after type juggling.” Whereas === results in “TRUE if $a is equal to $b, and they are of the same type.” So this is not the issue.
I hope this helps.
-
This reply was modified 7 years, 3 months ago by
Dan.