php - WooCommerce Changing Simple Product to Variable and Vice Versa, but how to get new variations to show on the frontend? -
php - WooCommerce Changing Simple Product to Variable and Vice Versa, but how to get new variations to show on the frontend? -
i creating plugin ties runit scheme showing onhand products in woocommerce. requires changing products via cron job update them, simple products variable products , vice versa depending on quantity of stock , variations of these products, change. have working code, updates these products in backend, showing right variations, however, not update on front end end. new variations, when editing variable products, not show on front end end when viewing actual product itself. still see old variations in there. how update variations utilize new variations automatically, instead of having nail update
button in backend administration when editing product?
is there sort of function needs called updating variations in woocommerce i'm not aware of? using array , serializing before updating meta_value meta_key _product_attributes
in wp_postmeta table, so:
function processbasicproperties(array $properties) { $return = array(); $position = 0; if (!empty($properties)) { if (!empty($properties['siz'])) { ++$position; $size = !is_array($properties['siz']) ? array($properties['siz']) : array_unique($properties['siz']); $return['size'] = array( 'name' => 'size', 'value' => count($size) > 1 ? implode(' | ', $size) : $size[0], 'is_visible' => count($size) > 1 ? 0 : 1, 'is_variation' => count($size) > 1 ? 1 : 0, 'is_taxonomy' => 0, 'position' => $position ); } if (!empty($properties['ext'])) { ++$position; $extension = !is_array($properties['ext']) ? array($properties['ext']) : array_unique($properties['ext']); $return['extension'] = array( 'name' => 'extension', 'value' => count($extension) > 1 ? implode(' | ', $extension) : $extension[0], 'is_visible' => count($extension) > 1 ? 0 : 1, 'is_variation' => count($extension) > 1 ? 1 : 0, 'is_taxonomy' => 0, 'position' => $position ); } // styles not added attributes variable products, instead, variable products, style goes overall sku of product (general properties) // so, in short, variable products should not have key set. if (!empty($properties['style'])) { ++$position; $return['style'] = array( 'name' => 'style', 'value' => htmlspecialchars($properties['style'], ent_quotes), 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0, 'position' => $position ); } if (!empty($properties['color'])) { ++$position; $colors = !is_array($properties['color']) ? array($properties['color']) : array_unique($properties['color']); $return['color'] = array( 'name' => 'color', 'value' => count($colors) > 1 ? htmlspecialchars(implode(' | ', $colors), ent_quotes) : htmlspecialchars($colors[0], ent_quotes), 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0, 'position' => $position ); } if (!empty($properties['gender'])) { ++$position; $return['gender'] = array( 'name' => 'gender', 'value' => htmlspecialchars($properties['gender'], ent_quotes), 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0, 'position' => $position ); } if (!empty($properties['season'])) { ++$position; $return['season'] = array( 'name' => 'season', 'value' => htmlspecialchars($properties['season'], ent_quotes), 'is_visible' => 1, 'is_variation' => 0, 'is_taxonomy' => 0, 'position' => $position ); } } homecoming $return; }
this function returns proper array serialized , inputted wp_postmeta
table meta_value
meta_key
= _product_attributes
. each variation has meta_key of attribute_size
, meta_key of attribute_extension
meta_value
equals value of specific variation required within wp_postmeta
table posts variation id.
i'm @ loss, trying update variations of variable product, or when converting simple product variable product, needs updated. shows fine in backend admin panel of product, when going actual product page, still shows old product variations. way show new one's go backend admin panel of product , nail update
button, shows of new variations. how programmatically? thought possible? must i'm overlooking here? perhaps there terms somewhere need updating?
functions have tried, failed update product new variations, s little = variation id 181342
, l big = variation id 181343
id
column of of wp_posts
table or post_id
column of wp_postmeta
table variation:
wp_set_object_terms(181342, 's', 'size'); wp_set_object_terms(181343, 'l', 'size');
and
do_action( 'woocommerce_create_product_variation', 181342 ); do_action( 'woocommerce_create_product_variation', 181343 );
none of these update product variation shows on front end end. still shows old variations on front end end. how size s
, l
showing on front end end?
along updating product attributes, have update product variations database.
for example, while deleting product variations, have remove wp_posts table
you can refer link more details woocommerce - cannot delete product variation
php wordpress woocommerce
Comments
Post a Comment