• Resolved jaceejoef

    (@jaceejoef)


    Hi,

    I am two CPTs (product and order), and I am using the pods form to add and edit posts on them.
    https://pods.io/docs/code/pods/form/

    When I add a new order (CPT), I want to update the number of stocks (custom field) in product (CPT).

    Is that possible? Is there a hook for that?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @jaceejoef

    You’ll have to add your own logic to trigger the remote product updates for stock.
    This can be done using PHP. See the WordPress hook save_post:
    https://developer.www.ads-software.com/reference/hooks/save_post/

    Honestly, sounds like you are creating a eCommerce solution. Why not use WooCommerce?

    Cheers, Jory

    Thread Starter jaceejoef

    (@jaceejoef)

    Hi Jory,

    Thank you for your response. For some reason, it’s not firing. I’ve also been trying to use transition post status hooks but still nothing.

    add_action('save_post_orders', 'jja_save_me', 10, 3);
    add_action('save_post', 'jja_save_me', 10, 3);
    function jja_save_me($post_id, $post, $update) {
    	error_log('WATCH ME');
    	$date = new DateTime();
    	
    	// Gather post data.
    	$my_post = array(
    		'post_title'    => $date->getTimestamp(),
    		'post_content'  => 'This is my post.',
    		'post_status'   => 'publish'
    	);
    
    	// Insert the post into the database.
    	wp_insert_post( $my_post );
    }

    re:woocommerce
    I’m actually doing an inventory system. Just a side project for our mini retail business. I originally plan to use woocommerce but, so far, I only need its product list feature so I just choose to create my own CPT instead of using a bulky woocommerce. Our order transactions are face-to-face so I also don’t need the order online feature of woocommerce.

    Thread Starter jaceejoef

    (@jaceejoef)

    Did another test.

    If I manually use the wp_insert_post, the save_post hook is firing. If I use the pods form to create a new post, save_post hook is not firing.

    • This reply was modified 4 years, 3 months ago by jaceejoef.
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hi @jaceejoef

    Then there must be something that is preventing this because Pods actually uses wp_insert_post as well.
    https://github.com/pods-framework/pods/blob/main/classes/PodsAPI.php#L248-L252

    Maybe a plugin conflict?
    https://docs.pods.io/faqs/plugin-theme-conflicts/

    Cheers, Jory

    Thread Starter jaceejoef

    (@jaceejoef)

    Hi @keraweb

    Yes, you’re right. It’s a plugin conflict. It has a conflict with Oxygen Builder which is something I can’t afford to deactivate.

    Here’s how I found out the conflict.

    Anyways, these are the activated plugins I’ve been using:

    • Oxygen Builder
    • Pods
    • Panda Pods Repeater
    • Code Snippets
    • WPS Hide Login

    Among those five, I can only deactivate WPS Hide Login since the rest are the main plugins that help me create the website. After deactivating WPS Hide Login, the post transition hooks is still not working. So what I did is setup a fresh install of WordPress and install those four plugins. I create a test CPT, test pods form, test page and save_post hook code. And it works!

    At this point, I don’t know what causes the issue in the original website so I plan to recreate everything part-by-part and test the save_post hook each time. The first I did is to create the base template in Oxygen. After applying the base template on the page with my test form, the save_post hook stop working. So the culprit is Oxygen!

    The error logs didn’t return any error message so I don’t know how to fix this. And I can’t deactivate oxygen since it’s my builder.

    In case anyone wants to investigate this, here’s my setup:

    • WordPress 5.5.3
    • Oxygen 3.6.1
    • Pods 2.7.24
    • Panda Pods Repeater Field 1.4.7
    • Code Snippets 2.14.0

    Other functionalities are custom code in Code Snippets.

    For now, I will look for another free form that can handle the pods repeater or maybe just create my own form (I already have the code anyway).

    I will mark this as resolved, even though it’s not really resolved, since this needs further investigation on either Oxygen or Pods.

    Plugin Author Jory Hogeveen

    (@keraweb)

    My guess is that updating a page within the Oxygen editor doesn’t fire the Post update hook but maybe a different one?
    Please contact their support on this matter!

    Cheers, Jory

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hook After Frontend Form Submission’ is closed to new replies.