php - How to get the Variation ID in a Woocommerce product -
i'm trying in plugin i'm writing variation id of products. here's 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 error:
deprecated: non-static method wc_product_variation::get_variation_id() should not called statically, assuming $this 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.
<?php $product_obj = new wc_product_factory(); $product = $product_obj->get_product($product); if ($product->product_type == 'variable'): $children = $product->get_children( $args = '', $output = object ); foreach ($children $key=>$value) { $product_variatons = new wc_product_variation($value); if ( $product_variatons->exists() && $product_variatons->variation_is_visible() ) { $variations[$value] = $product_variatons->get_variation_attributes(); } } endif;
Comments
Post a Comment