Support » Plugin: Woody code snippets - Insert Header Footer Code, AdSense Ads » Snippet runs in functions.php but not in the Snippet plugin

  • william333

    (@william333)


    Hi,

    I have a code snippet provided by a plugin support to impeach their commission system to create commissions over Sub-orders in Woocommerce.

    Here is the code

    if ( class_exists( 'YITH_Stripe_Connect' ) ) {
     if ( ! function_exists( 'yith_wcsc_process_order_commissions_custom' ) ) {
     function yith_wcsc_process_order_commissions_custom( $value, $order_id
     ) {
     $is_suborder  = wp_get_post_parent_id( absint( $order_id ) );
     if ( $is_suborder ) {
     $value = false;
     }
     return $value;
    
     }
    
          add_filter( 'yith_wcsc_process_order_commissions', 'yith_wcsc_process_order_commissions_custom', 10, 2 );
     }
    }

    It works fine if I set it in functions.php but does not run in the snippet plugin. I guess this is because the snippet runs before the theme loading or something. Any clue?

    Thanks a lot for your help and your time.

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

    (@webtemyk)

    Hello.

    function yith_wcsc_process_order_commissions_custom( $value, $order_id ) {
    	$is_suborder = wp_get_post_parent_id( absint( $order_id ) );
    	if ( $is_suborder ) {
    		$value = false;
    	}
    
    	return $value;
    
    }
    
    add_filter( 'yith_wcsc_process_order_commissions', 'yith_wcsc_process_order_commissions_custom', 10, 2 );
    
    Thread Starter william333

    (@william333)

    Hi @artem thanks.

    This code of your is suppose to replace the totality of my snippet? Od is it just a part?

    Why in your opinion this is happening?

    My problem is that I have a long list of snippets made by Yith and that all of them seem to behave the same way so I may need to understand of to solve the issue by myself.

    Thanks for your help.

    Thread Starter william333

    (@william333)

    Basically you say to take of the first lines?

    if ( class_exists( 'YITH_Stripe_Connect' ) ) {
     if ( ! function_exists( 'yith_wcsc_process_order_commissions_custom' ) ) {
    Plugin Author Artem

    (@webtemyk)

    It is possible that you haven’t initialized the YITH_Stripe_Connect class yet when the snippet is triggered, so the snippet doesn’t work. Since you don’t use this class in the snippet code, you need to remove the check for its existence.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Snippet runs in functions.php but not in the Snippet plugin’ is closed to new replies.