• Resolved chefnelone

    (@chefnelone)


    Hi,

    Is there a hook fired when a woocommerce coupon is created?

    I need to fire an action just at a coupon creation.

    Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter chefnelone

    (@chefnelone)

    It seems like implementing this code: code will allow me to use a hook like this:

    function after_new_coupon_created( $coupon_id, $coupon ){
        // your code here.
    }
    add_action( 'woocommerce_new_coupon', 'after_new_coupon_created', 10, 2 );

    Should I create custom plugin to embed the code? Are an easier way to add this code?

    • This reply was modified 3 years, 3 months ago by chefnelone.
    • This reply was modified 3 years, 3 months ago by chefnelone.
    • This reply was modified 3 years, 3 months ago by chefnelone.
    Thread Starter chefnelone

    (@chefnelone)

    I just try adding the code in functions.php but there is something wrong in these code. My site shows a critical error message:

    “Fatal error: Cannot declare class WC_Coupon_Data_Store_CPT, because the name is already in use in /usr/home/t16/www/wp-content/themes/flatsome-child/functions.php on line 708”.

    Line 708 is this:

    class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Data_Store_Interface, WC_Object_Data_Store_Interface {

    @chefnelone

    Seems the code you’re using is conflicting with the Flatsome theme.

    Can you enable Storefront theme to see if it works there?

    Thread Starter chefnelone

    (@chefnelone)

    It seems now that I should not add this code code as I said avobe. My mistake.Then the error is irrelevant since I delete the code

    But then this hook should print “It works” at the coupon creation. But it does not print the text.

    function after_new_coupon_created( $coupon_id, $coupon ){
        echo "It works";
    }
    add_action( 'woocommerce_new_coupon', 'after_new_coupon_created', 10, 2 );
    Plugin Support B C. a11n

    (@battouly)

    Hey @chefnelone,

    Where exactly do you expect to see the “It works” message?

    What are you trying to achieve with the snippet above?

    Thanks!

    Thread Starter chefnelone

    (@chefnelone)

    Hey!

    I expected to see the text at the top of the page. Maybe I should use something else to output this in chrome console. Can you tell me how to do this?

    I need to fire an action to create another coupon code in a booking system which has its own coupon system. Sort of coupon systems synchronization.

    Thanks!

    • This reply was modified 3 years, 2 months ago by chefnelone.

    Hi @somlaweb – what I would recommend trying to do is to use a plugin such as Show Hooks. It will show you all the hooks that are getting fired on the page and their sequence. It will also allow you to troubleshoot your code to see if you are hooking incorrectly for your action.

    Let us know how the troubleshooting goes!

    Thread Starter chefnelone

    (@chefnelone)

    Hi Katerna,

    I enabled the plugin but I see a lot of hooks in the coupon creation page.
    Not sure how to use this.

    Mirko P.

    (@rainfallnixfig)

    Hi @chefnelone,

    I see a lot of hooks in the coupon creation page

    That’s correct, the plugin when enabled will show all hooks fired on the page.

    If you require further assistance with custom development tasks you could reach out to some of the official WooCommerce development partners via this link below:

    https://woocommerce.com/customizations/

    Thread Starter chefnelone

    (@chefnelone)

    I just need to know the name of the hook/action.
    I don’t believe I should find a developer for this.
    Thanks anyway.

    Hi @chefnelone

    Kindly be aware that this specific forum is more focused on the default WooCommerce core features. We are unable to provide support for customizations per our Support Policy.

    As already recommended, you might get more insights by posting your question on the above channel for developers. I can also recommend the following places for more development-oriented questions:

    I hope this helps!

    We’ve not seen any activity on this thread for a while, so I’m marking this thread as resolved. If you have further questions, please feel free to open a new topic.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Is there a hook fired when a woocommerce coupon is created?’ is closed to new replies.