• djwilko12

    (@djwilko12)


    Hello,

    It seems the receipent of the gift card only receives the email when the status is “completed”, right? Is there a way to change this? So, the person received the notification when the order is PROCESSING instead of COMPLETED. Is it possible?

    On the other hand, how can i exclude cash as a payment option for when someone tried to buy a gift card?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Pablo Pérez

    (@pperez001)

    Hi there,

    If you want to only send the gift card when the order is on “processing” you can use the following code in the functions.php of your theme:

    if( !function_exists('yith_ywgc_generate_gift_card_on_order_status') ) {
        add_filter('yith_ywgc_generate_gift_card_on_order_status', 'yith_ywgc_generate_gift_card_on_order_status');
        function yith_ywgc_generate_gift_card_on_order_status() {
    
            return array('processing' );
    
        }
    }

    As for removing payment methods, you can use the WooCommerce hooks to remove the payment and check for the items of the cart for example:

    function remove_payment_method_for_gift_cards( $gateways ) {
    	if ( is_checkout() ) {
    		$cart_items = WC()->cart->get_cart();
    
    		$condition = false;
    
    		foreach ( $cart_items as $item ) {
    			
    			$product = wc_get_product($item['product_id'] );
    			if ( 'gift-card' === $product->get_type() ) {
    				$condition = true;
    				break;
    			}
    		}
    
    		if ( $condition ) {
    			unset( $gateways['cod'] );
    		}
    	}
    
        return $gateways;
    }
    
    add_filter( 'woocommerce_available_payment_gateways', 'remove_payment_method_for_gift_cards' );

    You set any payment method you have.

    I hope this can help you.

    Thread Starter djwilko12

    (@djwilko12)

    Thank you Pablo!

    For the payment method, if i add only the gift card, the payment gets hidden correctly. But if i add to cart the gift card and also a tangible product, the payment method should be visible again. How to do that? The idea is to hide the payment method ONLY when the user tries to buy just the gift card.

    Thanks!

    Plugin Support Juan Coronel

    (@juaancmendez)

    Hello there,

    Please try replacing the second code with this new one:

    if ( ! function_exists( 'remove_payment_method_for_gift_cards' ) ) {
    ? ? function remove_payment_method_for_gift_cards( $gateways ) {
    ? ? ? ? if ( is_checkout() && 1 == WC()->cart->get_cart_contents_count() ) {
    ? ? ? ? ? ? $cart_items = WC()->cart->get_cart();
    ? ? ? ? ? ? $condition = false;
    ? ? ? ? ? ? foreach ( $cart_items as $item ) {
    
    ? ? ? ? ? ? ? ? $product = wc_get_product($item['product_id'] );
    
    ? ? ? ? ? ? ? ? if ( 'gift-card' === $product->get_type() ) {
    ? ? ? ? ? ? ? ? ? ? $condition = true;
    ? ? ? ? ? ? ? ? ? ? break;
    ? ? ? ? ? ? ? ? }
    ? ? ? ? ? ? }
    
    ? ? ? ? ? ? if ( $condition ) {
    ? ? ? ? ? ? ? ? unset( $gateways['cod'] );
    ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? ? ? return $gateways;
    ? ? }
    ? ? add_filter( 'woocommerce_available_payment_gateways', 'remove_payment_method_for_gift_cards', 99 );
    }

    Let us know any news.

    Best regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘order status for receiving gift card’ is closed to new replies.