Nested shortcode functions accessing variable

After a bit of lateral thinking and lots of testing I was able to come up with a solution that negated the need for scope crossing variables, or using a global variable for that matter. The code goes like this: Split the nested $content(nested shortcodes) into single shortcodes with preg_match_all Apply do_shortcode to each shortcode … Read more

Save custom attributes of product in woocommerce

Finally I got it working with next code: $product = wc_get_product($productId); $attrName=”my_attribute”; $attrValue=”some value” $attr = new WC_Product_Attribute(); $attr->set_name( $attrName ); $attr->set_options( [$attrValue] ); $attr->set_visible(1); $attr->set_variation(1); $attr->set_position(0); $attr->set_id( 0 ); $attrs[$attrName] = $attr; $product->set_attributes($attrs); $product->save();