How to find your action in admin-ajax.php file? - wordpress

I am using woo commerce plugin for my eCommerce website. There are some order listed on my dashboard. When I change status of an order from processing to completed we click on button.
Here is my action goes:
if ( in_array( $the_order->post_status, array('wc-pending', 'wc-on-hold', 'wc-processing') ) )
$actions['complete'] = array(
'url' => wp_nonce_url( admin_url( 'admin-ajax.php?action=upen-mark-order-complete&order_id=' . $the_order->id ), 'upen-mark-order-complete' ),
'name' => __( 'Dispatched', 'dokan' ),
'action' => "complete",
'icon' => '<i class="fa fa-truck"> </i>'
);
But when I am looking into admin-ajax.php file there is no order_id getting. I am confused that where these attributes are we getting to change order status like action, order_id etc.

You should read wp_ajax_(action).
based on your given code, there should be something like this implemented somewhere... maybe on your theme files or plugin files..
add_action( 'wp_ajax_upen-mark-order-complete', 'my_action_callback' );
function my_action_callback() {
$order_id = $_GET['order_id'];
wp_die();
}
additionally,
With notepad++ you can search it in your files like this..

Please try this in your themes functions.php
function mysite_woocommerce_order_status_completed( $order_id ) {
echo $order_id; exit; // you will get order ID here , when you are updating order status to completed.
}
add_action( 'woocommerce_order_status_completed','mysite_woocommerce_order_status_completed' );

Related

How to add short description in WooCommerce checkout page

Thanks for reading, Just had a issue regarding WooCommerce, I want to add a short description checkout page of below billing field.
How to add short description in WooCommerce checkout page of below billing field?
I tried add function, custom code but failed with error.
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
$post_data = get_post( $cart_item['product_id'] );
$other_data[] = array( 'name' => 'description', 'value' => $post_data->post_excerpt );
return $other_data;
}
I was used this code but it is showing inner product info table.
There's no real reason to call get_post(). The $product object is stored in the $cart_item array and the $post object is stored inside the $product. This gets the product's excerpt (aka the short description) to show up in the cart and in the checkout. Now, it isn't likely the make the description show up on the order received page, or in the my account area, or in emails, etc since the only place that the woocommerce_get_item_data filter appears is in the cart class.
One thing to take note of, WooCommerce 2.7 is a major rewrite of WooCommerce and $_product->post->post_excerpt will result in PHP notices about directly accessing product properties. So I've suggested both the 2.6 and 2.7 compatible approaches.
add_filter( 'woocommerce_get_item_data', 'wc_checkout_description_so_27900033', 10, 2 );
function wc_checkout_description_so_27900033( $other_data, $cart_item )
{
$_product = $cart_item['data'];
// Use this for WC2.7
//$other_data[] = array( 'name' => 'description', 'value' => $_product->get_short_description() );
// Use this for WC2.6
$other_data[] = array( 'name' => 'description', 'value' => $_product->post->post_excerpt );
return $other_data;
}

Change custom post type slug from Settings > Permalinks page

add_action( 'init', 'register_my_types' );
function register_my_types() {
register_post_type( 'movies',
array(
'labels' => array(
'name' => __( 'Movies' ),
'singular_name' => __( 'Movie' )
),
'public' => true,
'rewrite' => array(
'slug' => 'films'
),
)
);
}
I can use the following to change the slug from my plugin settings page (on save to get 'filme' from a field):
add_filter( 'register_post_type_args', 'movies_register_post_type_args', 10, 2 );
function movies_register_post_type_args( $args, $post_type ) {
if ( 'movies' === $post_type ) {
$args['rewrite']['slug'] = 'filme';
}
return $args;
}
But, I want to be able to modify the "films" slug from Settings > Permalinks page.
How do I add a custom post type slug to Settings > Permalinks page?
Update:
In the end I created a form field in the plugin settings page and I updated the filter like this:
function register_post_type_args( $args, $post_type ) {
if ($this->plugin_name === $post_type ) {
$slug=get_option( $this->plugin_name.'_slug' );
if($args['rewrite']['slug']!=$slug){
$args['rewrite']['slug'] = $slug;
}
}
return $args;
}
But I'm still looking for a way to change the slug from Settings / Permalinks.
You can use plugins like this:
Toolset Types
Custom Post Type UI
You should use WordPress Settings API:
Add a setting field for your slug, attached to the permalinks page with add_settings_field()
Write the callback function to display the <input> fied in the page
Write the function that record the value in the database after the form submission with update_option()
All you have to do then is modify your register_post_type() function. The get_option() function will return the value that has to be affected to slug (don't forget to test its existence).

How to show my plugin in WordPress?

can any one help to solve a problem?
Just For example:
If I have one site wpnpl.com.np
I wannt to give access to the files of a plugin like if they type
wpnpl.com.np/npl they will access the features of the plugin
How to do this???Any Idea
First create plugin short code in your plugin core file
function bartag_func( $atts ) {
$atts = shortcode_atts( array(
'foo' => 'no foo',
'baz' => 'default baz'
), $atts, 'bartag' );
return "foo = {$atts['foo']}";
}
add_shortcode( 'bartag', 'bartag_func' );
After that create a page in wp-admin with slug npl and content with
[bartag foo="bar"]

Wordpress Profile File / Page

I would like to create a file in the Wordpress theme, where i will add my own code, edit profile, show profile information, and perhaps an ability to insert posts / meta data programmatically.
So it needs to be www.mysite.com/profile.php or www.mysite.com/profile/
I do not want to use Buddy Press or any other plugin.
I know how the template system works, i do not want a page template.
It will probably be a class, later on, i do not want to change .htaccess file, and if i must i would appreciated filter function how to do this from functions.php
Basically just a simple .php file i can link to, located in theme root.
include('../../../wp-load.php');
and write any code i would like to.
Any creative solution that is not too "hacky" would be appreciated.
Spent around 2 days googling bashing my head on this, before i decided to ask question.
Thank you very much.
Ok, I managed to do this, took me 2 days to figure it out. Here is how I managed to do it:
Make a plugin folder.
In that plugin folder make 1x php file. so index.php
Ok so first thing we need to register plugin I did it like this, in your index.php paste
this code.
function activate_profile_plugin() {
add_option( 'Activated_Plugin', 'Plugin-Slug' );
/* activation code here */
}
register_activation_hook( __FILE__, 'activate_profile_plugin' );
Then we need a function when you register a plugin only once register profile pages.
function create_profile_page( $title, $slug, $post_type, $shortcode, $template = null ) {
//Check if the page with this name exists.
if(!get_page_by_title($title)) {
// if not :
$page_id = -1;
$page_id = wp_insert_post(
array(
'comment_status' => 'open',
'ping_status' => 'open',
'post_content' => $shortcode,
'post_author' => 1, // Administrator is creating the page
'post_title' => $title,
'post_name' => strtolower( $slug ),
'post_status' => 'publish',
'post_type' => strtolower( $post_type )
)
);
// If a template is specified in the function arguments, let's apply it
if( null != $template ) {
update_post_meta( get_the_ID(), '_wp_page_template', $template );
} // end if
return $page_id;
}
}
Ok so we created function which programatically register pages. It has 5 paramethers.
is Title
Slug
Post type
Shortcode.
Template
For the shortcode template you need to make a shortcode with the complete page output
and add it as a parameter to this function, so for registration page it will be a shortcode with the registration forms etc.
For example :
function registration_shortcode(){
echo 'Wellcome to Registration page';
}
add_shortcode('registration_output', 'registration_shortcode');
Next thing we need to call it once only when plugin loads.
so we do this :
function load_plugin() {
if ( is_admin() && get_option( 'Activated_Plugin' ) == 'Plugin-Slug' ) {
delete_option( 'Activated_Plugin' );
/* do stuff once right after activation */
// example: add_action( 'init', 'my_init_function' );
create_profile_page('Registration', 'registration', 'page', '[registration_output]');
create_profile_page('Profile', 'profile', 'page', '[profile_shortcode]');
create_profile_page('Profil Edit', 'profile-edit', 'page', '[edit_shortcode]');
}
}
add_action( 'admin_init', 'load_plugin' );
Ok so this will execute only once when plugin loads and it will create 3 Pages, which are Profile, Registration and Profile Edit.
And that's it, you have your front-end user profile blank pages, and you can write page output in shortcodes ,create more pages, put any forms or elements you like and create decent profile (which doesn't have any stuff you don't need in it like plugins. )
Hope this helps, it was painful for me to figure this out. Cheers!

WordPress: Add action for each custom post type

Im looking to add an action for each of the custom post types registered on my WordPress site (when a custom post type is published).
Now I could just manually add one for each of the types I have like:
add_action( 'publish_book', 'function_title_to_call' );
add_action( 'publish_movie', 'function_title_to_call' );
...
But I wanted to ask if there is a way it could be done so its all automated?
I tried the following without luck:
$arguments = array(
'public' => true,
'_builtin' => false
);
$all_post_types = get_post_types( $arguments, 'names', 'and' );
foreach ( $all_post_types as $one_post_type ) {
add_action( 'publish_' . $one_post_type, 'function_title_to_call' );
}
Any suggestions?

Resources