Skip Navigation

[Resolved] Product update post meta

This support ticket is created 7 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 25 replies, has 3 voices.

Last updated by Bochnacki 7 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#550003

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - thanks for all the details.

Your site is too complicated to understand as it has hundreds of fields but its OK 🙂

Now, I review your site and as I understand, on checkout page you have two different products one is for home display and one is for top display.

Now, you want that if user by product with product ID 1174 (home), it should display at home page and when user buy this product the taxonomy term "inhome" should be assigned automatically so that with view one home page which is displaying product you can add filter there and you filter that view by inhome taxonomy term - correct?

#550029

Ok, I added for view "In home" this new taxonomy as a filter with the option "inhome". The 'home page' still does not display.

#550234

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I did not ask you to make changes but could you please confirm the flow which I explained in my previous reply.

What I was saying that and I want confirmation on that:
I review your site and as I understand, on checkout page you have two different products one is for home display and one is for top display. - correct?

Now, you want that if user by product with product ID 1174 (home), it should display at home page and when user buy this product the taxonomy term "inhome" - correct?

That means taxonomy term "inhome" should be assigned automatically so that with view one home page which is displaying product you can add filter there and you filter that view by inhome taxonomy term - correct?

See this entry - I've set payments taxonomy term "inhome" for this product:
=> hidden link

Check the view where I've added taxonomy query filter for taxonomy payments - section "Query Filter":
=> hidden link

As - taxonomy term "inhome" is set its displaying on home page:
=> hidden link

So - what I want to confirm finally is - when user will buy product with product ID 1174 (home), it should display at home page (so - we need to automate the process of assigning "inhome" payment taxonomy term when we buy this product) - correct?

#550267

Yes, exactly.

#550300

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok great - I'm assigning this ticket to Luo, he will get in touch with you as soon as possible by tomorrow.

#550302

Thanks for the help.

#550599

Dear Bochnacki,

I just got this thread, and I am reading through this thread and checking it in your website, will feedback if there is anything found

#550607

I just added below codes into your theme/functions.php:


add_action( 'woocommerce_order_status_completed', 'add_featured_option', 10, 1 );
function add_featured_option( $order_id ) {	
    $cred_form_id = get_post_meta($order_id, '_cred_form_id', true);
	$cred_form_ids = array(39);// here you can add more CRED form IDs    
	if(	in_array($cred_form_id, $cred_form_ids) ){
        $order = wc_get_order( $order_id );	
        $post_id = get_post_meta($order_id, '_cred_post_id', true); 
		$terms = array();
        foreach ( $order->get_items() as $item ) {
            $product_id = $item['product_id'];
			if($product_id == 1174){ // this is product ID of "home"
				$terms[] = 795; // this is term ID of "inhome"
			}
        } 
		if(!empty($terms)){
			$term_taxonomy_ids = wp_set_object_terms( $post_id, $terms, 'payment' );
		}
	}
}

Please test again, check if it is what you want. thanks

More help:
https://codex.wordpress.org/Function_Reference/wp_set_object_terms

#550670

Luo, your code works well - when you add to the "In home" option, the post is shown on the main page.

I have 6 CRED forms for adding posts and 3 highlighting options. I understand that I need to repeat this code for everyone, right?
If so, unfortunately I do not know how - I did it, but wrong, because it does not work.
1. I repeated your code and changed the product ID, CRED form ID, and the "Payment" option ID - for the "featured" option.
2. I added a new post by selecting the "In home" and "featured" options.
3. Post is added, but not on the home page.

What should the shortcode for "featured" or "intop" look like? I want to put this on the list of posts to see if it works, but I do not know how to write such a shortcode now.

I understand that the Custom field "featured-opt" I have previously created is not useful and can be deleted, right?

#550674

To modify the PHP codes, you can try these:

1) This line:

$cred_form_ids = array(39);// here you can add more CRED form IDs  

For example you can apply the custom codes to more CRED forms, like this:

$cred_form_ids = array(39, 123, 456);// here you can add more CRED form IDs  

Please replace 123, 456 with your CRED form IDs

2) you can specific other products post to specific term, for example, from:

            if($product_id == 1174){ // this is product ID of "home"
                $terms[] = 795; // this is term ID of "inhome"
            }

To:

            if($product_id == 1174){ // this is product ID of "home"
                $terms[] = 795; // this is term ID of "inhome"
            }
            if($product_id == 123){ // this is product ID of "featured"
                $terms[] = 456; // this is term ID of "featured"
            }

Please replace 123 with product ID of "featured", replace 456 with term ID of "featured"

For other new questions: What should the shortcode for "featured" or "intop" look like?
please create new thread for them, this will help other users to find the answers. thanks

#550681

OK thank you. Now the code is working correctly.

"What should the shortcode for "featured" or "intop" look like?" - without this I can not verify whether the "featured" and "intop" options work correctly. But ok - I will create a new topic.

Thank for help!