I’m trying to get in a plugin I’m writing the variation ID of products. Here’s what I wrote:
class mass {
public function __construct()
{
add_action('woocommerce_product_after_variable_attributes',array($this,'thfo_mass'));
}
public function thfo_mass()
{
$id = WC_Product_Variation::get_variation_id();
//$lenght = get_post_meta($id,'_length');
//$dimensions = wc_get_dimension(24750, 'cm');
var_dump($id);
}
I only get an error:
Deprecated: Non-static method WC_Product_Variation::get_variation_id() should not be called statically, assuming $this from incompatible context in path/to/plugins/thfo-raw-material-for-woocommerce/class/mass.php on line 19
Notice: Undefined property: mass::$variation_id in path/to/wp-content/plugins/woocommerce/includes/class-wc-product-variation.php on line 257
int(0)
try this.
get_variation_id
is not a static method at all.You need to create an instance/object of
WC_Product_Variation
, then you can use it.Like —
Please check this result is here: How to get Woocommerce Variation ID?
Here’s what I’ve managed to figure out so far:
Firstly, to get the colour:
Then in my foreach loop that is generating the checkboxes:
Then you can use
current( $product_shipping_classes )->term_id
orcurrent( $product_shipping_classes )->slug
orcurrent( $product_shipping_classes )->name
.The searchForVariants function is in my
functions.php
file:The
$available_variations
array is already in the storefront theme in thevariable.php
but I am using a child theme so copied the template file to make these changes.