GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Plugin for woocommerce that changes product title after purchase (https://gfy.com/showthread.php?t=1371061)

CaligulaDrusilla 12-11-2023 03:29 PM

Plugin for woocommerce that changes product title after purchase
 
Does anyone here know if that exists?

fris 01-03-2024 09:08 AM

what do you want to do to the title?

you will have to use the action, which contains the order id, and you will have to get all the product ids in that order in the callback function, and update the post object and have it save.

im unsure on what you want to do with the title, so i cant really give an example before knowing the use case.


is the action to use

woocommerce_order_status_completed

this is untested, but its a start to get where you want to go.

dont use on a live site. if you have a demo playground enable WP_DEBUG in wp-config.php incase you have any errors.

Code:

<?php

add_action('woocommerce_order_status_completed', 'change_title_on_competed_status' 10, 1);

function change_title_on_competed_status( $order_id ) {

    $order = wc_get_order( $order_id );

    foreach ( $order->get_items() as $item_id => $product_item ) {
        $product_id = $product_item->get_product_id();
        $product_title = $product_item->get_name();
        $args = array('ID' => $product_id, 'post_title' => $product_title . ' add text on to end if you want?');
        wp_update_post( $args );
    }
}



All times are GMT -7. The time now is 02:55 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc