logo
Tags down

shadow

Get the catalog visibility for a product in a SQL query on Woocommerce


By : d.kustec
Date : October 17 2020, 08:10 PM
Hope this helps The following SQL query will display for a given product ID the catalog visibility as follow:
code :
$product_id = 37;

$result = $wpdb->get_var( "
    SELECT COUNT(tr.object_id)
    FROM {$wpdb->prefix}terms as t
    JOIN {$wpdb->prefix}term_taxonomy AS tt ON t.term_id = tt.term_id
    JOIN {$wpdb->prefix}term_relationships AS tr ON tt.term_taxonomy_id = tr.term_taxonomy_id
    WHERE t.name = 'exclude-from-catalog'
    AND tr.object_id = $product_id
" );

echo $result; // 0 for visible | 1 for not visible


Share : facebook icon twitter icon

Woocommerce: Display Product Variation Description on shop catalog page


By : Francisco Mikael Rib
Date : March 29 2020, 07:55 AM
Hope this helps Updated: As I dont have and I don't use your commercial plugin and as your question is not so clear… There is 2 possibilities:
1) You would like to add the short description (from the parent variable product) for the product variations that are displayed (with your plugin) on woocommerce archives pages (like shop …), just like the other products.
code :
add_action( 'woocommerce_after_shop_loop_item_title', 'add_short_description', 9 );
function add_short_description() {
    global $post;

    // 1. Product variation
    if ($post->post_type = 'product_variation'){
        $post_parent_id = $post->post_parent; // Get the parent variable product ID
        $post_parent = get_post( $post_parent_id ); // Get the parent variable WP_Post object
        $text = $post_parent->post_excerpt; // Get the short description from the parent variable product
    } 
    // 2. Other cases (simple, variable …)
    else {
        $text = $post->post_excerpt;
    }

    $maxchar = 75; // Maximum number of characters

    $text = preg_replace ('~\[[^\]]+\]~', '', $text ); // Remove shortcodes

    // Remove all html symbols
    //$text = strip_tags( $text);

    // Crop
    if ( mb_strlen( $text ) > $maxchar ){
        $text = mb_substr( $text, 0, $maxchar );
        $text = preg_replace('@(.*)\s[^\s]*$@s', '\\1 ...', $text );
    }
    echo "<span class='catalog-short-desc'>$text</span>";
}
// For Woocommerce versions 3+ only
add_action( 'woocommerce_after_shop_loop_item_title', 'add_short_description', 9 );
function add_short_description() {
    global $post, $product;

    // 1. Product variation
    if ( $product->is_type('product_variation') ){
        // Get the product variation description
        // short description doesn't exist for product variations
        $text = $product->get_description();

        // If the product variation description is empty, we get the parent short description
        if( empty( $text ) ){
            $parent_id = $product->get_parent_id(); // The parent variable product ID
            $parent_product = wc_get_product( $parent_id ); // The parent WC_Product object
            $text = $parent_product->get_short_description();
        }
    }
    // 2. Other cases (simple, variable …)
    else {
        $text = $product->get_short_description();
    }

    $maxchar = 75; // Maximum number of characters

    $text = preg_replace ('~\[[^\]]+\]~', '', $text ); // Remove shortcodes

    // Remove all html symbols
    //$text = strip_tags( $text);

    // Crop
    if ( mb_strlen( $text ) > $maxchar ){
        $text = mb_substr( $text, 0, $maxchar );
        $text = preg_replace('@(.*)\s[^\s]*$@s', '\\1 ...', $text );
    }
    echo "<span class='catalog-short-desc'>$text</span>";
}

Change product visibility via PHP on Woocommerce 3+


By : Raphael
Date : March 29 2020, 07:55 AM
wish of those help I have a feature on my store that allows me to auto-generate a product quote, after the quote's attributes, prices, and shipping rules, I create a new product on the fly. , it should be something like this:
code :
$terms = array( 'exclude-from-search', 'exclude-from-catalog' ); // for hidden..
wp_set_post_terms( $prod_ID, $terms, 'product_visibility', false );

Update the product visibility in Woocommerce 3


By : user1019456
Date : March 29 2020, 07:55 AM
I wish this helpful for you Since Woocommerce 3 the products visibility is now handled by the 'product_visibility' custom taxonomy for the terms 'exclude-from-catalog' and 'exclude-from-search'… See this thread or this one too.
So you should use instead the WC_Product CRUD setter methods set_catalog_visibility() this way:
code :
// Get an instance of the product variation from a defined ID
$child_product = wc_get_product(child_id);
// Change the product visibility
$child_product->set_catalog_visibility('visible');
// Save and sync the product visibility
$child_product->save();

Add custom column product visibility to admin product list in Woocommerce 3


By : Don Hoffman
Date : March 29 2020, 07:55 AM
This might help you There are some errors and mistakes in your code. Also since Woocommerce 3 product visibility is handled by Woocommerce custom taxonomy 'product_visibility'. Try the following instead:
code :
// Add a new column to Admin products list with a custom order
add_filter( 'manage_edit-product_columns', 'visibility_product_column', 10);
function visibility_product_column($columns){
    $new_columns = [];
    foreach( $columns as $key => $column ){
        $new_columns[$key] = $columns[$key];
        if( $key == 'price' ) { // Or use: if( $key == 'featured' ) {
             $new_columns['visibility'] = __( 'Visibility','woocommerce');
        }
    }
    return $new_columns;
}

// Add content to new column raows in Admin products list
add_action( 'manage_product_posts_custom_column', 'visibility_product_column_content', 10, 2 );
function visibility_product_column_content( $column, $product_id ){
    global $post;

    if( $column =='visibility' ){
        if( has_term( 'exclude-from-catalog', 'product_visibility', $product_id ) )
            echo '<em style="color:grey;">' . __("No") . '</em>';
        else
            echo '<span style="color:green;">' . __("Yes") . '</span>';
    }
}

Woocommerce How can I display product attributes under product title on catalog page?


By : MW1
Date : March 29 2020, 07:55 AM
I wish this help you According to your query i can to use on wc_get_product_terms() method for this case as
in the products loop use
Related Posts Related Posts :
  • How to add subitem totals to get groupitem total in laravel view
  • php how to get xml tags
  • how to execute a cmd in sql?
  • Mongo $addToSet an Array
  • Integrating isotope.js with Wordpress loop
  • Create Admin settings for SugarCRM custom module
  • Storing special characters in DB in such a way to display properly on site and still find image with the same name
  • Obtain value tag from xml
  • PHP Mail with attachment - but file is empty
  • PHP Multiple require, same function
  • Traverse XML file to find products recursively
  • PHP is not displaying 'success' message after writing data to JSON, but data gets added
  • Locate specific text in Google Sheets using the API
  • Laravel, convert to uuid text from uuid binary upon creating model
  • Creating formula
  • Grouped Array data
  • Wordpress get_option() with index key from string
  • PHP Laravel: A better way than these if statements
  • Trying to build my query by fetching column names from the selected table
  • Two values in the same column
  • Exceeding 10 nested forwards?
  • Ternary in associative arrays in PHP
  • simplexml_load_file won't fetch data with an Array
  • php mysql looking how to check if there are no result
  • Laravel filters won't work when trying to add them
  • Checking for duplicate mysql data with bootstrap validator
  • yii2 Error of dynamic client validation URL - Cannot read property 'test' of undefined
  • PHP Script to handle end of year calculation automatically?
  • Saved html is not the same as it's output in the browser
  • Wordpress shows only one post
  • SQL record retrieval
  • PHP return true if all method calls inside a foreach method return true
  • Unexpected error after transfering website to new server - mix of php and html in IF
  • Remove the last part of the comma in foreach in PHP?
  • the_author_meta() wont show inline text in { }
  • How do I create an error handler in php that redirects the user if a specific error occurs?
  • PHPInfo / Valet - Two different PHP versions
  • Connect an active directory or LDAP with PHP
  • How to assign a variable from another file to a class constant?
  • How to remove array index from php array?
  • How to handle multiple paginations with one link
  • Inverting order of exhibition of the elements in PHP
  • Slim 3 withRedirect problem and parameters
  • using Laravel 5.7 : how can i get json value name from an array ?
  • I See a Lot of `<open></close>` Tag Sets That Contain NO Data, Doesn't This Negate the Tag?
  • Calling a class and function using variable
  • php unset foreach loop is not unsetting the value of array
  • Error! The command "tesseract" was not found. (PHP thiagoalessio)
  • show data from json
  • Laravel - Views - router() doesn't work or I just dumb
  • Return foreach values inside string
  • Internal server error 500 Laravel 5.4 AJAX
  • Add text to a file with PHP SSH2
  • Setting up named routes within a subdomain group in Laravel 5.7
  • Yii2: How to add two fields and NULLS LAST in orderby() of Find() using mysql
  • Removing string characters form mysqli database and utilize two variables derived from database
  • How to update one table from two different pages in laravel
  • Select non-parentheses and non-quotes comma
  • How to filter php array by min/max value
  • how to send an array of URI's from php to python and print it there
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org