• Resolved ehsan991

    (@ehsan991)


    Hello ,

    I used a part of Code for Once-Buy in my shop

    // Deny purchase if already purchased
    add_filter( 'woocommerce_is_purchasable', 'deny_purchase_if_already_purchased', 9999, 2 );
     function deny_purchase_if_already_purchased( $is_purchasable, $product ) {
       if ( is_user_logged_in() && wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) {
          $is_purchasable = false;
          echo "already_purchased";
       }
       return $is_purchasable; 
    }

    and in woocommerce it works well
    but woo-wallet gets in trouble & The wallet can no longer be charged
    — after click on Topup i see a message {already_purchased}

    Please Help me
    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter ehsan991

    (@ehsan991)

    I found that, this plugin use WooCommerce to charge wallets ( Private Product)

    how can i change my code only for Public Products ?

    Plugin Author Subrata Mal

    (@subratamal)

    @ehsan991 Please use the attached updated code.

    // Deny purchase if already purchased
    add_filter( 'woocommerce_is_purchasable', 'deny_purchase_if_already_purchased', 9999, 2 );
     function deny_purchase_if_already_purchased( $is_purchasable, $product ) {
    	if(get_wallet_rechargeable_product()->get_id() === $product->get_id()){
    		return $is_purchasable;
    	}
    	if ( is_user_logged_in() && wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) ) {
    		$is_purchasable = false;
    		echo "already_purchased";
    	}
       return $is_purchasable; 
    }
    Thread Starter ehsan991

    (@ehsan991)

    Thank you very much, it was very helpful
    But when the wallet-product is in the cart, the cart page does not open

    debug.log:

    #35 {main}
    thrown in mywebsite/wp-content/plugins/woocommerce/includes/class-wc-cart.php on line 2032

    • This reply was modified 2 years, 10 months ago by ehsan991.
    Plugin Contributor Moumita Adak

    (@moumitaadak)

    @ehsan991 Please share detailed error log.

    Thread Starter ehsan991

    (@ehsan991)

    The problem was solved with a small change
    I put the code so that others can use it as well

    // Deny purchase if already purchased
    add_filter( 'woocommerce_is_purchasable', 'deny_purchase_if_already_purchased', 9999, 2 );
     function deny_purchase_if_already_purchased( $is_purchasable, $product ) {
       if ( is_user_logged_in() && wc_customer_bought_product( '', get_current_user_id(), $product->get_id() ) && get_post_status()!='private' ) {
          $is_purchasable = false;
          echo "already_purchased";
       }
       return $is_purchasable; 
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘interfere with Woocommerce’ is closed to new replies.