• Hi there,

    I am looking for a php snippet to add the following to the Gift Card code I generated with the YITH gift card plugin. The code below does not work. Any ideas how to correct?

    <?php
    
    add_action( 'save_post_shop_coupon', 'my_child_after_coupon_save', 10, 3 );
    
    function my_child_after_coupon_save( $post_id, $post, $update ) {
       update_post_meta( $post_id, 'is_voucher', 'yes' );
    }

    Best
    Muleque

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author YITHEMES

    (@yithemes)

    Hi Muleque,
    hope you are doing well! ??

    The code you sent is executed when you save a default WooCommerce coupon, for this reason, it’s not working with the YITH Gift Cards.

    If you want to add the post meta “is_voucher” when a gift card is pruchased and the code created, you have to add the next code in the functions.php of your active theme:

    if( ! function_exists( 'yith_ywgc_add_new_meta_to_gift_card' ) ){
    	function yith_ywgc_add_new_meta_to_gift_card( $gift_card ) {
    		update_post_meta( $gift_card->ID, 'is_vourcher', 'yes');
    	}
    	add_action('yith_ywgc_after_gift_card_generation_save', 'yith_ywgc_add_new_meta_to_gift_card', 10 );
    }

    Please, note that it will work only on the new gift card purchases.

    Could you check it, please?

    Have a nice day!

    Thread Starter muleque

    (@muleque)

    so I do not know if it actually changes the meta (how to debug this behavior?) I only know that it still does not do the changes I hoped for.

    Best
    Muleque

    Plugin Author YITHEMES

    (@yithemes)

    Hi Muleque,

    After the gift card is generated, you can check the gift card metadata in the wp_postmeta table from the database, searching it by the gift card post ID, and check if this meta is correctly added.

    Could you take a look and let us know, please?

    Have a nice day!

    Thread Starter muleque

    (@muleque)

    It actually worked, but was not the intended outcome another plugin this was aimed at.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add meta data’ is closed to new replies.