"wc term_exists category" Code Answer's

You're definitely familiar with the best coding language TypeScript that developers use to develop their projects and they get all their queries like "wc term_exists category" answered properly. Developers are finding an appropriate answer about wc term_exists category related to the TypeScript coding language. By visiting this online portal developers get answers concerning TypeScript codes question like wc term_exists category. Enter your desired code related query in the search bar and get every piece of information about TypeScript code related question on wc term_exists category. 

wc term_exists category

By EnrybiEnrybi on Apr 23, 2021
// 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();
}

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the TypeScript based application and are stuck on wc term_exists category can get a collection of related answers to their query. Programmers need to enter their query on wc term_exists category related to TypeScript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about wc term_exists category for the programmers working on TypeScript code while coding their module. Coders are also allowed to rectify already present answers of wc term_exists category while working on the TypeScript language code. Developers can add up suggestions if they deem fit any other answer relating to "wc term_exists category". Visit this developer's friendly online web community, CodeProZone, and get your queries like wc term_exists category resolved professionally and stay updated to the latest TypeScript updates. 

TypeScript answers related to "wc term_exists category"

View All TypeScript queries

TypeScript queries related to "wc term_exists category"

Browse Other Code Languages

CodeProZone