logo
down
shadow

Move "in stock" up on Woocommerce product page


Move "in stock" up on Woocommerce product page

Content Index :

Move "in stock" up on Woocommerce product page
Tag : php , By : user183442
Date : November 29 2020, 09:01 AM

seems to work fine You have moved your link tag for the itemprop="availablity", which is showing in the html within the itemprop="offers" however you have not moved the actual stock html that is contained within


This is the current content around the code you provided

<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
    <p class="price"><span class="woocommerce-price-before"><font><font>from € 849 </font></font></span><span class="woocommerce-price-after"> </span></p>
<meta itemprop="price" content="0">
    <meta itemprop="priceCurrency" content="EUR">
    <link itemprop="availability" href="http://schema.org/InStock">
</div>
<?php
    // Availability
    $availability      = $product->get_availability();
    $availability_html = empty( $availability['availability'] ) ? '' : '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>';

    echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product );
?>
<?php
    echo $product->get_price_html();

    if ( $availability = $product->get_availability() ) {
        $availability_html = empty( $availability['availability'] ) ? '' : '<p class="stock ' . esc_attr( $availability['class'] ) . '">' . esc_html( $availability['availability'] ) . '</p>';
        echo apply_filters( 'woocommerce_stock_html', $availability_html, $availability['availability'], $product );
    }
?>

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to echo "# in stock" from product page on WooCommerce?


Tag : development , By : Sascha Brossmann
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I try to print again "In stock" inside the product page but I cant find solution how can I echo it. On the image is by default but I want to have it again on the same page, how can i echo / print that.
function wc_dropdown_variation_attribute_options( $args = array() ) {
    global $product;
    $variations = $product->get_available_variations();


        $args = wp_parse_args( apply_filters( 'woocommerce_dropdown_variation_attribute_options_args', $args ), array(
            'options'          => false,
            'attribute'        => false,
            'product'          => false,
            'selected'         => false,
            'name'             => '',
            'id'               => '',
            'class'            => '',
            'show_option_none' => __( 'Choose an option', 'woocommerce' ),
        ) );
        $options   = $args['options'];
        $product   = $args['product'];
        $attribute = $args['attribute'];

        $name      = $args['name'] ? $args['name'] : 'attribute_' . sanitize_title( $attribute );
        $id        = $args['id'] ? $args['id'] : sanitize_title( $attribute );
        $class     = $args['class'];
        if ( empty( $options ) && ! empty( $product ) && ! empty( $attribute ) ) {
            $attributes = $product->get_variation_attributes();
            $options    = $attributes[ $attribute ];

        }
        $html = '<select id="' . esc_attr( $id ) . '" class="' . esc_attr( $class ) . '" name="' . esc_attr( $name ) . '" data-attribute_name="attribute_' . esc_attr( sanitize_title( $attribute ) ) . '">';
        if ( $args['show_option_none'] ) {
            $html .= '<option value="">' . esc_html( $args['show_option_none'] ) . '</option>';
        }
        if ( ! empty( $options ) ) {

            /*if ( $product && taxonomy_exists( $attribute ) ) {

                // Get terms if this is a taxonomy - ordered. We need the names too.
                $terms = wc_get_product_terms( $product->get_id(), $attribute, array( 'fields' => 'all' ) );
                foreach ( $terms as $term ) {
                    if ( in_array( $term->slug, $options ) ) {
                        $html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
                    }
                }
            } else {*/
                foreach ( $options as $option ) {

                    foreach ($variations as $variation) {
                        if($variation['attributes'][$name] == $option) {
                            $stock = esc_html($variation['max_qty']);
                        }
                    }
                    if( $stock == 0) {
                        $stock_text = ' - (Out of Stock)';
                        $class = 'option-out-of-stock';
                        $disabled = 'disabled';
                    } elseif ($stock < 5 ) {
                        $stock_text = ' - Only ' . $stock . ' left!';
                        $class= 'option-hurry';
                        $disabled = '';
                    } elseif ($stock < 6) {
                        $stock_text = ' - Only a few left!';
                        $class = 'option-few';
                        $disabled = '';
                    } else {
                        $stock_text = ' - (In Stock)';
                        $class = '';
                        $disabled = '';
                    }
                    // This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
                    $selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
                    $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . ' class="'.$class.'" '.$disabled.'>' . $option  .  $stock_text .'</option>';
                //}
            }
        }
        $html .= '</select>';

        echo apply_filters( 'woocommerce_dropdown_variation_attribute_options_html', $html, $args );
    }

Get the count of "in stock" product variations for a variable product in Woocommerce


Tag : php , By : Alex S
Date : March 29 2020, 07:55 AM
will help you To get the "in stock" variations count of a variable product on single product pages you can:
1) Use only php and Woocommerce WC_Product methods:
global $product;
$count_in_stock = 0;

if ( $product->is_type( 'variable' ) ) {
    $variation_ids = $product->get_children(); // Get product variation IDs

    foreach( $variation_ids as $variation_id ){
        $variation = wc_get_product($variation_id);
        if( $variation->is_in_stock() )
            $count_in_stock++;
    }
}

// Your condition
if( $count_in_stock <= 1 ){
   // Do something
}
global $wpdb, $product;
$product_id = $product->get_id();
$count_in_stock = 0;

if ( $product->is_type( 'variable' ) ) {
    $count = $wpdb->get_col("
        SELECT count(p.ID) as in_stock_count FROM {$wpdb->prefix}postmeta as pm
        INNER JOIN {$wpdb->prefix}posts as p ON pm.post_id = p.ID
        WHERE p.post_type LIKE 'product_variation' AND p.post_parent = $product_id
        AND pm.meta_key LIKE '_stock_status' AND pm.meta_value LIKE 'instock'
    ");

    $count_in_stock = reset($count);
}

// Your condition
if( $count_in_stock <= 1 ){
   // Do something
}      

Remove "can be backordered" from product page stock display in Woocommerce


Tag : php , By : Magnus
Date : March 29 2020, 07:55 AM
it should still fix some issue Updated
The following code will remove "(can be backordered)" text from the product availability text, when product is in stock and backorders are allowed (with a customer notification):
add_filter( 'woocommerce_get_availability_text', 'filter_product_availability_text', 10, 2 );
function filter_product_availability_text( $availability, $product ) {

    if( $product->backorders_require_notification() ) {
        $availability = str_replace('(can be backordered)', '', $availability);
    }
    return $availability;
}

Add a Contact Form to "Out of Stock" product Variations in WooCommerce


Tag : php , By : NewGirl
Date : March 29 2020, 07:55 AM
I wish this helpful for you The following code will add a contact form to a selected out of stock product variation:
add_filter( 'woocommerce_available_variation', 'form_to_out_of_stock_product_variations', 10, 3 );
function form_to_out_of_stock_product_variations( $data, $product, $variation ) {
    if( ! $data['is_in_stock'] )
        $data['availability_html'] .= do_shortcode('[contact-form-7 id="6513" title="Out of Stock Form"]');

    return $data;
}
add_action('woocommerce_single_product_summary', 'add_contact_form', 30,2);
function add_contact_form() {
    global $product;

    if( ! $product->is_in_stock( ) && ! $product->is_type('variable') )
       echo do_shortcode('[contact-form-7 id="6513" title="Out of Stock Form"]');
}

echo "Sale" on woocommerce product page before product title if the product category is "store-pickup&quo


Tag : wordpress , By : Heals1ic
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Need help, I want to echo "sale" on the woocommerce product page on top of product title if the product is on the "store-pickup" product category. , Try the follows code -
add_action( 'woocommerce_single_product_summary', 'show_store_pickup', 1 );
function show_store_pickup() {
    global $product; 
    if ( has_term( 'store-pickup', 'product_cat', $product->get_id() ) ) 
        echo __( "Sale!", "text-domain" );  
}
Related Posts Related QUESTIONS :
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • ZF2 Routing Multiple Controllers based on route constraints
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • How to test authentication using Laravel Dusk?
  • PHP parse_str not getting all $_GET variables
  • Variable issues in php class
  • Get orders between dates in Codeigniter
  • Eloquent Special Chars Issue
  • Keeping leading zeros column Mysql
  • Current level navigation in Wordpress
  • Add a custom text to WooCommerce cart items if the product has a specific shipping class
  • Error connecting to CommissionJunction Token : [60] SSL certificate problem: unable to get local issuer certificate
  • How do I add a new key value pair to an object in PHP?
  • Http post request to php with dart
  • How to add a route in with blade into parameters of a component
  • How can i get the source of a 777 - CHMOD php file?
  • Convert 2010-04-16 16:30:00 to "Tomorrow Afternoon"
  • How can I hide a $_GET variable to be more secured in PHP?
  • Login to Gmail Inbox using Curl?
  • Upload Excel or CSV file to MySQL with PHP
  • Outlook Marking Email as Junk Email
  • Upload an image using class.upload.php via AJAX, display image in form using jQuery
  • mysql_connect() causes page to not display (WAMP)
  • How to limit a users uploaded image size using PHP
  • What's the difference whether or not to run PHP in safe mode?
  • Logging in to a website cURL
  • Using php to create a password system with chinese characters
  • PHP is not called properly in IE using set interval function in Javascript
  • How to read pdf, ppt, xl, doc files content into a string in php/python
  • php script for currency conversion
  • In PHP... best way to turn string representation of a folder structure into nested array
  • PayPal for Indian Rupees (INR) any solution
  • PHP Deployment to Live Server
  • Ideal Multi-Developer Lamp Stack?
  • How can I save an image from a file input field using PHP & MySQL?
  • Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in
  • Connecting to external MySQL DB from a web server not running MySQL
  • Is it possible to add custom fields to a Drupal taxonomy term?
  • PHP 6.0 - Roadmap?
  • jQuery wait for ajax call to be over before continuing
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com