Dan
Forum Replies Created
-
Also getting the same issue
Forum: Plugins
In reply to: [WooCommerce Sample] Deactivate stock management for samples ?@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.
Forum: Plugins
In reply to: [WooCommerce Sample] Deactivate stock management for samples ?@cvetter If in doubt place the code at the end of your functions.php file
@delacourcorp Great! I am glad to have helped 🙂
Forum: Plugins
In reply to: [WooCommerce Sample] Deactivate stock management for samples ?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 );Forum: Plugins
In reply to: [WooCommerce Sample] Not WorkingYou can enable free shipping on the sample and set the sample price for free under the “Sample” module settings on a product’s admin page.
Forum: Plugins
In reply to: [WooCommerce Sample] Deactivate stock management for samples ?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 );