Support » Plugin: WOO Stickers by Webline » Adding the sold out sticker to the Cart Page

  • doronshe

    (@doronshe)


    Hi
    If you’d like to see the sticker on the cart page for sold out items here are 7 steps that I added to the plugin. (Works for me on WP 5.0.1 WC 3.5.2).

    /public_html/wp-content/plugins/woo-stickers-by-webline/public/css/woo-stickers-by-webline-public.css
    =====================================================================================================
    Add at the BOTTOM
    —————–
    .woocommerce table.shop_table .woocommerce-cart-form__cart-item td {
    position: relative !important;
    }
    .woocommerce-mini-cart .woosticker {
    display: none;
    }
    /public_html/wp-content/plugins/woo-stickers-by-webline/public/class-woo-stickers-by-webline-public.php
    =======================================================================================================
    line 65 Add ,[new line]’enable_sticker_cart’ => ‘no’
    —————————————————-
    // Merge with defaults
    $this->general_settings = array_merge ( array (
    ‘enable_sticker’ => ‘no’,
    ‘enable_sticker_list’ => ‘no’,
    ‘enable_sticker_detail’ => ‘no’,
    ‘enable_sticker_cart’ => ‘no’
    ), $this->general_settings );

    line 285 (after previous addition) just before the last } that closes the class
    ——————————————————————————-
    /**
    * Call back function for show sold product badge on cart.
    *
    * @return string
    * @param string $product_image The product image.
    * @param string $cart_item.
    * @param string $cart_item_key.
    * @author Doron Shemesh
    */
    public function show_cart_product_soldout_badge($product_image, $cart_item, $cart_item_key)
    {
    if ($this->general_settings[‘enable_sticker’] == “yes” &&
    $this->sold_product_settings[‘enable_sold_product_sticker’] == “yes”) {

    if( (!is_product() && $this->general_settings[‘enable_sticker_cart’] == “yes”) ) {

    $product = $cart_item[‘data’];

    $classSoldPosition=(($this->sold_product_settings[‘sold_product_position’]==’left’) ? ((is_product())? ” pos_left_detail ” : ” pos_left ” ) : ((is_product())? ” pos_right_detail ” : ” pos_right “));

    $classSold=(($this->sold_product_settings[‘sold_product_custom_sticker’]==”)?(($this->sold_product_settings[‘enable_sold_product_style’] == “ribbon”) ? (($this->sold_product_settings[‘sold_product_position’]==’left’)?” woosticker soldout_ribbon_left “:” woosticker soldout_ribbon_right “) : (($this->sold_product_settings[‘sold_product_position’]==’left’)?” woosticker soldout_round_left “:” woosticker soldout_round_right “)):”woosticker custom_sticker_image”);

    if($product->get_type()==’variable’) {

    $total_qty=0;

    $available_variations = $product->get_available_variations();

    foreach ($available_variations as $variation) {

    if($variation[‘is_in_stock’]==true){
    $total_qty++;
    }

    }

    if($total_qty==0){
    if($this->sold_product_settings[‘sold_product_custom_sticker’]==”) {
    echo ‘<span class=”‘.$classSold . $classSoldPosition .'”>Sold Out</span>’;
    }
    else {
    echo ‘<span class=”‘ . $classSold . $classSoldPosition . ‘” style=”background-image:url(‘.$this->sold_product_settings[‘sold_product_custom_sticker’].’);”> Sold Out </span>’;
    }
    }

    }
    else {
    if (! $product->is_in_stock ()) {
    if($this->sold_product_settings[‘sold_product_custom_sticker’]==”) {
    echo ‘<span class=”‘.$classSold . $classSoldPosition .'”>Sold Out</span>’;
    }
    else {
    echo ‘<span class=”‘ . $classSold . $classSoldPosition . ‘” style=”background-image:url(‘.$this->sold_product_settings[‘sold_product_custom_sticker’].’);”> Sold Out </span>’;
    }
    }
    }
    }
    }
    return $product_image;
    }

    /public_html/wp-content/plugins/woo-stickers-by-webline/includes/class-woo-stickers-by-webline.php
    ==================================================================================================
    line 214 just before closing the function define_public_hooks
    ————————————————————-
    //action to show sold out product badge on Cart page
    // By Doron Shemesh
    $this->loader->add_filter(‘woocommerce_cart_item_thumbnail’, $plugin_public, ‘show_cart_product_soldout_badge’, 11, 3 );

    /public_html/wp-content/plugins/woo-stickers-by-webline/admin/class-woo-stickers-by-webline-admin.php
    ========================================================================================================
    line 150 Add ,[new line]’enable_sticker_cart’ => ‘no’
    —————————————————-
    // Merge with defaults
    $this->general_settings = array_merge ( array (
    ‘enable_sticker’ => ‘no’,
    ‘enable_sticker_list’ => ‘no’,
    ‘enable_sticker_detail’ => ‘no’
    ), $this->general_settings );

    line 215 (after previous addition) at the end of the function register_general_settings
    —————————————————————————————
    // By Doron Shemesh
    add_settings_field ( ‘enable_sticker_cart’, ‘Enable Sticker On Cart Page:’, array (
    &$this,
    ‘enable_sticker_cart’
    ), $this->general_settings_key, ‘section_general’ );

    line 423 (after previous additions) before
    /**
    * New Product Settings :: Enable Stickers
    ———————————————-
    /**
    * General Settings :: Enable Sticker On Cart Page
    *
    * @return void
    * @var No arguments passed
    * @author Doron Shemesh
    */
    public function enable_sticker_cart() {
    ?>
    <select id=’enable_sticker_cart’
    name=”<?php echo $this->general_settings_key; ?>[enable_sticker_cart]”>
    <option value=’yes’
    <?php selected( $this->general_settings[‘enable_sticker_cart’], ‘yes’,true );?>>Yes</option>
    <option value=’no’
    <?php selected( $this->general_settings[‘enable_sticker_cart’], ‘no’,true );?>>No</option>
    </select>
    <p class=”description”>Select wether you want to enable sticker feature on cart page or not.</p>
    <?php
    }

    Enjoy

    • This topic was modified 7 months ago by  doronshe.
  • The topic ‘Adding the sold out sticker to the Cart Page’ is closed to new replies.