• Resolved studiovitas

    (@studiovitas)


    hi, i’m trying to send tags while registering in a form integrated with cf7.
    What I see is that the tag is different based on the post category.
    For example, in the SEO category, when you sign up, I want the category name to be passed to the tag, and therefore the tag to be SEO.
    il codice di seguito, è quello usato per inserire i tag, e funziona perfettamente

    add_filter( 'mc4wp_integration_contact-form-7_subscriber_data', 'vts_dinamic_tag_mc4wp_cf7',10,2);
    
    function vts_dinamic_tag_mc4wp_cf7(MC4WP_MailChimp_Subscriber $subscriber, $cf7_form_id){
        $tag = 'seo';
    	$subscriber->tags[] = $tag;
    	return  $subscriber; 
    }

    but if i try to create that field in dynamic, it doesn’t happen. nothing.

    add_filter( 'mc4wp_integration_contact-form-7_subscriber_data', 'vts_dinamic_tag_mc4wp_cf7',10,2);
    
    function vts_dinamic_tag_mc4wp_cf7(MC4WP_MailChimp_Subscriber $subscriber, $cf7_form_id){
        $vtsCurrentUrl = 'https://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ];
    	$vtsCatTag = get_the_category(url_to_postid($vtsCurrentUrl));
    	 
    	
        $tag = $vtsCatTag[0]->slug;
    	$subscriber->tags[] = $tag;
    	return  $subscriber; 
    }

    outside of this function, I still manage to get the category name. The problem arises inside the filter.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Lap

    (@lapzor)

    Try passing $vtsCurrentUrl, or $_SERVER[ ‘REQUEST_URI’ ]; to a Mailchimp text field, see what you have there and work from there.

    Thread Starter studiovitas

    (@studiovitas)

    always through the filter? is there any documentation on how to do this?

    Thread Starter studiovitas

    (@studiovitas)

    I understand, I saw that the result is the url of the form and not of the page. this is because the action starts when the submit button of the form is pressed and not when the page is generated.
    then the variable returns:

    https://my-site.com/wp-json/contact-form-7/v1/contact-forms/3794/feedback.

    Do you know if there is a way to capture the url of the page from which the form is submitted?

    Thread Starter studiovitas

    (@studiovitas)

    For those who need it, this is the solution:
    adding a tag with a value equal to the category slug of the post from which the form is filled out:

    
    
    add_filter( 'mc4wp_integration_contact-form-7_subscriber_data', 'vitas_dinamic_tag_mc4wp_cf7',10);
    
    function vitas_dinamic_tag_mc4wp_cf7(MC4WP_MailChimp_Subscriber $subscriber){
        $formPageUrl = $_SERVER[ 'HTTP_REFERER' ];
    	$catList= get_the_category(url_to_postid($formPageUrl));
    	$mainCat = $catList[0]->slug;
       
    	$subscriber->tags[] = $mainCat;
    	return  $subscriber; 
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘dinamic tag based on post category’ is closed to new replies.