Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

wc term_exists category

// Get an instance of the WC_Product object
$product = wc_get_product( $product_id );

$term_names = $product->get_attribute( 'Platform' ); // Can have many term names (coma separated)

$term_names = explode( ',', $term_names);
$term_ids   = [];

// Loop through the terms
foreach( $term_names as $term_name ) {
    // Get the term ID and check if it exist
    if( $term_id = term_exists( $term_name, 'product_cat' ) ) {
        // Add each term ID in an array
        $term_ids[] = $term_id; 
    } 
}
// Append the product category terms in the product 
if( sizeof($term_ids) > 0 ) {
    $product->set_category_ids( $term_ids );
    $product->save();
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: execute script when c# code gets executed 
Typescript :: gamemanager unity resets after reloading scene 
Typescript :: how to remove the last item from a collection powerapps 
Typescript :: whats ruby used for 
Typescript :: input deno 
Typescript :: from how many ways we can define props with typescript react 
Typescript :: when a vector in c++ is resized what happens to the elements of the vector 
Typescript :: react native paper 
Typescript :: <edit-config changes in this plugin conflicts with <edit-config changes in config.xml. Conflicts must be resolved before plugin can be added 
Typescript :: coldfusion arrayLast 
Typescript :: outside click hook react 
Typescript :: angular find and remove from string 
Typescript :: prototype design pattern typescript 
Typescript :: typescript string concatenation best practice 
Typescript :: promise.all inside useEffect 
Typescript :: Start Angular App In Localhost 
Typescript :: why important testng xml file 
Typescript :: run an applescript 
Typescript :: socket.io auth 
Typescript :: c# merge two lists different types 
Typescript :: styled components gatsby 
Typescript :: convert javascript to typescript 
Typescript :: dynamic key interface typescript 
Typescript :: Roblox Script wait 
Typescript :: dwayne johnson maui 
Typescript :: c# ienumerable wrap to know when its compltee 
Typescript :: How to store and mix types in an Array in typescript 
Typescript :: network analysis projects code python graph and histogram with data facbook 
Typescript :: Algebra is simply overlaying sets of equations onto the world around us. 
Typescript :: numpy select elements from array condition 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =