• Resolved webdev

    (@swapnilwebdev)


    When we added product to cart it saves our cart list when we are logged-in, and shows same cart product when we next time visit the site or cart,

    Now due to some reasons i have to remove some product from site so i move them to Draft status.
    now new users cannot see it and order it.
    but then person who have already added it to cart, the product is showing to them in cart list but they cannot click on it as its draft,
    they can also checkout including that draft product.
    That product should me removed from cart with showing some notice to user.

    Please provide solution for this issue.

    **Screenshots**
    https://prntscr.com/kzszut
    https://prntscr.com/kzt0op

    **To Reproduce**
    Steps to reproduce the behavior:
    1. Go to ‘shop page add any product to cart ‘
    2. Edit that product and set status to draft.
    3. Now Go to Cart page and try to Checkout, order will be placed with draft products.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi there,

    You can use ‘woocommerce_check_cart_items’ hook for cart page check and ‘woocommerce_before_checkout_process’ hook for
    checkour page check and write a common function which loops on items to check for the product status. If it’s status is draft then remove that product from cart.
    Function: WC()->cart->remove_cart_item($cart_item_key);

    Please let me know if you need any further information.

    Thread Starter webdev

    (@swapnilwebdev)

    Hi Kartik,
    Thanks for the replay
    But i think this issue needs to be fix in woocommerce update.

    • This reply was modified 6 years, 1 month ago by webdev.
    Joel Williams

    (@joelwills)

    Automattic Happiness Engineer

    Hi there!

    If you think it’s something that needs to be fixed in WooCommerce core itself, then you can open a bug report here:

    https://github.com/woocommerce/woocommerce/issues

    All the best!

    acafourek

    (@acafourek)

    You can use the woocommerce_is_purchasable filter to add your own validation step that will prevent un-published products from being added to the cart and will also remove any from the cart.

    My example:

    add_filter('woocommerce_is_purchasable', 'prefix_wc_is_purchasable', 10, 2);
    
    	function prefix_wc_is_purchasable( $is_purchasable, $object ) {
    		if ( get_post_status( $object->get_id() ) !== "publish" )
    			return false;
    		else 
    			return true;
    	}
    • This reply was modified 6 years ago by acafourek.
    • This reply was modified 6 years ago by acafourek.
    • This reply was modified 6 years ago by acafourek. Reason: Code block formatting + typo

    @acafourek, any thoughts on how to get the filter to work on Variations? It seems to work perfectly for non-variation products.

    @jbojang There is another filter woocommerce_variation_is_purchasable that you can find here: https://github.com/woocommerce/woocommerce/blob/99da8f4aa4f2dd95cca40ab11df6c460d3d1bb8c/includes/class-wc-product-variation.php#L514

    I haven’t tested it but the code suggests it will behave similarly. One thing to note though is that you’ll probably need to adapt the code above a bit since Variations can’t really be in draft or publish status themselves, they inherit the post status of their parent. So you probably want to adapt the code to check the post status of the parent?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Draft product checkout issue’ is closed to new replies.