Problem with automatic change of order status WooCommerce [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm having trouble with a function.
I want that after placing an order in the store, if the order value is zero, the order status will automatically change to completed.
Can anyone give a hint?
I'm using Change order status for virtual, downloadable, free or backorder products in WooCommerce answer code, but it's not quite what I would like.

You haven't told us much about your problem. Still, there's a woocommerce_checkout_order_created action available to you.
A snippet like this may help you.
function adam_check_order( $order ) {
/* examine $order for the criterion you want, then call your function */
}
add_action( 'woocommerce_checkout_order_creation_action', 'adam_check_order' );
In general, the way you get this kind of stuff to work is
Install WordPress's Code Snippets plugin or some other way rapidly to edit and run code on your site.
Put your site into WordPress debugging mode.
Look for a WordPress or Woocommerce hook (filter or action) that's invoked at the appropriate point in your workflow. Finding the correct hook can be challenging; they're not wonderfully documented. I use ctrl-f to search the web page listing the hooks. (If you use a filter hook be sure to return the filtered object passed to you.)
Write a snippet of code like my example.
Put print_r() calls into your snippet. That will make php-ish stuff show up in your page when the hook is invoked, and show you the contents of the data objects ($order in your case) passed to you.
Get things working.
Remove the print_r() calls and take the site out of debugging mode.

Related

Typo3 changing existing frontend via extension [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I got a website (Typo3 9.5) already configured with existing typoscript and a bunch of pages.
Now I want to create an extension which simply adds one line of code to every page when a checkbox in the backend for this specific page is set.
Like a "Show Editor [x]" checkbox which then adds a simple fixed to this exact page.
I know there must be an easy way to get this to work but I have no idea how to do it.
Right now I'm thinking about manipulating the PAGE object in Typoscript and just add a on 10000000 with all the needed variables inside. But there must be a better way.
Your Requirements are actually multiple tasks which can be seperated:
Backend UI
Fetching the Editor of the Page
display that data in the frontend
Backend UI
adding a checkbox to the TYPO3 Backend requires you to add TCA Overrides to define an addtional field for the pages table. and and ext_tables.sql to adapt the database schema (you need to store this value in the database)
Fetching the Editor of the Page
what is the editor of the page? is it the "author" field of the page record? the user who initally created the page? the person who created the most content elements on the page? this of course has to be solved by you.
in the similes way its just text field and you can use it right away in the typoscript for more complex scenarious you might create a viewHelper, dataProcessor or userFunc to resolve the Author.
display that data in the frontend
you now should have somehow fetched the user. and you need to "insert" it at the correct place in you page template. if its just a simple value it should be straight forward adapting add it to your typoscirpt PAGE object. or FLUIDTEMPLATE

Symfony 4 - How to organize my form collection? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
In my Symfony 4 project, I have a Validator entity that contains the 'order' and 'user' fields that refer to a user of my User entity.
The goal is to allow the site administrator to establish a list of users who can validate certain requests from other users, but with a specific order.
For example, the admin would establish the following list:
1. Philippe Dupont
2. Julia Robert
3. Joseph Dupuis
He would have the possibility on the page to dynamically add elements, or to change the order of the validators as he wishes by passing Joseph Dupuis in 1st position for example.
So, it would look a little like what we see on this page using a jQuery plugin
https://symfony-collection.fuz.org/symfony3/
(But I'm under Symfony 4 )
Image of what I want
The goal being the submission of the form to be able to obtain in this case 3 validator objects that will contain the correct order (1,2,3) with the right User elements according to what has been entered. And everything will be spent on the BDD.
Except that in addition to being able to do that, it would be necessary that on each fields text, there is an automatic filtering on the complete name of the user with each modification of the field.
So I would like to have your help to know how I should go about doing all this. Is this plugin the right solution? Is it easy to set up on Symfony 4? Ability to add a filter effect?
Thanks for your help !
Take what you want to do a step at a time. You are asking for 2 different things here, and there isn't a pre-built javascript library that will do both.
Start with creating your "Validator" input form form. It sounds like select2.js will help you with your auto-complete request. Your User field would be a EntityType or ChoiceType.
Then move on to creating a collection of these forms following the Symfony docs. The collection script you linked should work with Symfony 4 with tweaking, as form collections really didn't change much between 3.x and 4.x.

Wordpress: Link a post to posts of another category manually [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have an 'events' post type. I have another category called 'Speakers' and it has posts which are speakers.
When creating an event I need to select the speakers for each event through backend. I need to give an interface so that the admin could select the speakers for the event.
I recommend using the AdvancedCustomFields-Plugin. With this you can build a "relationship" between your post type 'events' and the 'speakers'. This way you can choose the 'speakers' on every 'event'.
The Plugin is well documented. See for yourself how it works:
http://www.advancedcustomfields.com/resources/relationship/
Without more details on what you need, it's hard to give a code example, but the idea would be to set up a meta box for that custom post type that runs a query for all speakers and displays them in a select box.
Adding Meta Boxes:
https://codex.wordpress.org/Function_Reference/add_meta_box
Running a Query:
https://codex.wordpress.org/Class_Reference/WP_Query
(this is for WP_Query, but there are also others, like get_posts, that you can use)
GENERAL STEPS
Create meta box for events custom post type
Within the meta box, put a select box with the query results for speaker custom post type
Make sure to save data within meta box on post's save
Get and display meta box data in template/page
If you could post more information, I can add some example code to help you out.

Generating quizz content from database dynamically from a plugin [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
My client is a college professor who wants to add online quizzes for his students on his Wordpress-powered website, among other things. So I'm building a custom plugin that allows him or any administrator to make these quizzes from the admin pages. All this info is saved in the mysql database in their own tables, no problem here. It's when showing the quizzes to the students/regular users of the blog that I got lost.
What I wanted was a way to generate these quizzes. At first I figured a $_GET parameter with the quiz's ID the student wants to do would do the trick, but then, where would that even go? Should I use a separate php file in the main directory of wordpress (and would that even work)?
Should I create a regular old post and slap the code with shortcodes? Should I work with custom post types? (But remember the quizzes are already created in the database and I feel making one post, custom or regular, for each quiz seems excessive and complicated. Can you even make a wordpress page dynamic and pass it a parameter?)
Or is there a way to use hooks to rewrite the main page to show my code instead of the loop (or any other place at all)? Or am I too far off and is there another method altogether?
You can do it as simply as using a custom template. For example, make a page called "Quiz" and a custom template called quiz.php. In that template you could simply look for the quiz id in the query string and then display it:
if($_GET['quiz_id']){
/** code to retrieve and output the quiz */
}
else{
/** code for them to select a quiz */
}
That's the bare bones approach. To do it in a slicker way you might use something like the rewrite endpoint API (http://codex.wordpress.org/Rewrite_API/add_rewrite_endpoint)
An example of that would be:
/** add a custom function to the init hook */
add_action('init', 'my_custom_endpoint');
/** custom endpoint for handling forms */
function my_custom_endpoint(){
add_rewrite_endpoint('forms', EP_ALL);
/** when pages are loaded, check to see if it's a form page and do something */
add_action( 'template_redirect', 'process_form' );
}
The EP_ALL is the endpoint mask -- it tells WordPress where to apply the new endpoint. You could have it apply only to pages, only to posts, etc. In this case you're adding your endpoint everywhere.
Then you have a function that actually processes the endpoint:
function process_form(){
global $wp_query;
/** check for your endpoint. A URL like site.com/forms/12 would set forms = 12 */
if(isset($wp_query->query_vars['forms'])){
/** the query var forms has a value, do something to show the form */
echo get_form($wp_query->query_vars['forms']);
}
}

Change site's title to match Google search [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I was developing a site for a parts distributor, when I ran into an SEO problem.
Basically, the business distributes many different brands, so I want to make it that, when a certain brand is searched, the title of the google result changes to that particular brand.
Example:
If Brand-X is searched on google, the result should appear as...
My Business - Brand-X distributor
I want it to lead to the same page though. Is there any valid way to do this, or will I have to settle with setting keywords for each of the brands, and a site description including them?
I want it to lead to the same page though.
That isn't possible. Google will show the title of the page at the time it was indexed.
Google indexes your pages first, and when someone searches google, they look in their index. The results they display are from their cached version, and not a live fetch from your site. Hope that clears things up.
Naah No Such way to play with Titles for search Engines!
Simply set the title in the HTML
<title>My Business - Brand-X distributor</title>
Google will display the title of the page for each webpage in the results.
Google will eventually reindex the page and show the new title.
...actually it is possible but it will require some work. I just finished something similar. Google accesses your page content very much the same as any other visitor so you need to actually create an illusion that each product have it's own page (even thought all is aiming to your product-id123.php for example). So you need to start with a page which will contain the list of every product you have and then generate dynamically a unique link for each of them.
This can be done by a simple PHP loop accessing an array of all the products and creating a link + title for each of them.
You will end-up with a very long page and it is better (if you have thousands of products) to separate this into separate pages based on the product category for example.
Then when you have all the product list pages done you can use the following script in the header of the main landing page.
<?php
if($_SERVER['REQUEST_URI'] == '/product-id123.php') {
$title = '<title>Product ID 123</title>';
} elseif ($_SERVER['REQUEST_URI'] == '/product-id456.php') {
$title = '<title>Product ID 456</title>'; // etc...
?>

Categories