• Resolved seascoot

    (@seascoot)


    I have a marketplace type site based on WC Vendors Pro. I would like to be able to have vendors sell gift cards that can only be used against the products listed on their individual store. It seems like this plugin does not allow restriction of applying a balance to certain products. Is this a function I am missing, or is this not possible?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author pimwick

    (@pimwick)

    We haven’t experimented with WC Vendors Pro, however if it is all one WooCommerce product catalog then likely our plugin won’t work without custom programming.

    While it isn’t possible to tie a gift card to a specific product directly in the plugin, you can implement this by using the pwgc_eligible_cart_amount hook.

    For example:

    function custom_pwgc_eligible_cart_amount( $eligible_amount, $cart ) {
        //
        // Set this to the Product IDs of the eligible products. Remove the numbers if all products are eligible.
        //
        $eligible_product_ids = array();
    
        //
        // Set this to the Product IDs of the ineligible products. Remove the numbers if all products are NOT eligible.
        //
        $ineligible_product_ids = array();
    
        foreach( WC()->cart->get_cart() as $cart_item ) {
            $valid_product = true;
    
            if ( in_array( $cart_item['product_id'], $ineligible_product_ids ) ) {
                $valid_product = false;
            }
    
            if ( !empty( $eligible_product_ids ) && !in_array( $cart_item['product_id'], $eligible_product_ids ) ) {
                $valid_product = false;
            }
    
            if ( !$valid_product )  {
                $eligible_amount -= $cart_item['line_total'];
            }
        }
    
        return max( 0, $eligible_amount );
    }
    add_filter( 'pwgc_eligible_cart_amount', 'custom_pwgc_eligible_cart_amount', 10, 2 );

    Depending on your needs you can set the Eligible Product IDs to pick a few products that can be purchased, or set the Ineligible Product IDs to block out a few products that are not allowed to be purchased with a gift card.

    The code will still allow the product(s) to be purchased, it just prevents the amounts from being paid by the gift card balance.

    Let me know if you have any questions!

    Plugin Author pimwick

    (@pimwick)

    Marking this thread as Resolved but let us know if you need anything else.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Compatibility with WC Vendors marketplace’ is closed to new replies.