• I am using this code snippet to mark products as “sold out” (or “vendido”):

    // colocar etiqueta de “vendido”
    add_action ( ‘woocommerce_before_shop_loop_item_title’, ‘vendido’);
    function vendido() {
    global $product;
    $estatus = get_post_meta ($product->get_id(), ‘estatus_del_negocio’, true);
    if ( $estatus == ‘vendido’ ) { echo ‘<span class=”onsale”>Vendido</span>’; }
    }

    It works fine, except that if that same product happen to be also “On Sale”, that tag takes precedence, and “Sold Out” is not shown. I need to reverse that precedence: if a product is both “On Sale” and “Sold out”, only the last tag should be shown.

    Thanks: René.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • You won’t want both flashes showing at the same time. Its got to be one or the other, so try something like:

    // remove the existing hook
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
    // add your custom hook
    add_action ( 'woocommerce_before_shop_loop_item_title', 'vendido', 10 );
    function vendido() {
      global $product;
      $estatus = get_post_meta ($product->get_id(), 'estatus_del_negocio', true);
      if ( $estatus == 'vendido' ) { 
        echo '<span class="onsale">Vendido</span>';
      } else {
        // its not sold out, so run the normal sale function
        woocommerce_show_product_loop_sale_flash();
      }
    }

    Sorry, not tested.

    If your theme has its own templates, the function names and priorities might be different.

Viewing 1 replies (of 1 total)
  • The topic ‘Sale! versus Sold Out!’ is closed to new replies.