WC_Post_Data::init PHP Method

init() public static method

Hook in methods.
public static init ( )
    public static function init()
    {
        add_filter('post_type_link', array(__CLASS__, 'variation_post_link'), 10, 2);
        add_action('woocommerce_deferred_product_sync', array(__CLASS__, 'deferred_product_sync'), 10, 1);
        add_action('set_object_terms', array(__CLASS__, 'set_object_terms'), 10, 6);
        add_action('transition_post_status', array(__CLASS__, 'transition_post_status'), 10, 3);
        add_action('woocommerce_product_set_stock_status', array(__CLASS__, 'delete_product_query_transients'));
        add_action('woocommerce_product_set_visibility', array(__CLASS__, 'delete_product_query_transients'));
        add_action('edit_term', array(__CLASS__, 'edit_term'), 10, 3);
        add_action('edited_term', array(__CLASS__, 'edited_term'), 10, 3);
        add_filter('update_order_item_metadata', array(__CLASS__, 'update_order_item_metadata'), 10, 5);
        add_filter('update_post_metadata', array(__CLASS__, 'update_post_metadata'), 10, 5);
        add_filter('wp_insert_post_data', array(__CLASS__, 'wp_insert_post_data'));
        // Status transitions
        add_action('delete_post', array(__CLASS__, 'delete_post'));
        add_action('wp_trash_post', array(__CLASS__, 'trash_post'));
        add_action('untrashed_post', array(__CLASS__, 'untrash_post'));
        add_action('before_delete_post', array(__CLASS__, 'delete_order_items'));
        add_action('before_delete_post', array(__CLASS__, 'delete_order_downloadable_permissions'));
        // Download permissions
        add_action('woocommerce_process_product_file_download_paths', array(__CLASS__, 'process_product_file_download_paths'), 10, 3);
    }

Usage Example

Ejemplo n.º 1
0
            $data['post_title'] = $order_title;
        } elseif ('product' === $data['post_type'] && isset($_POST['product-type'])) {
            $product_type = stripslashes($_POST['product-type']);
            switch ($product_type) {
                case 'grouped':
                case 'variable':
                    $data['post_parent'] = 0;
                    break;
            }
        }
        return $data;
    }
    /**
     * Some functions, like the term recount, require the visibility to be set prior. Lets save that here.
     *
     * @param int $post_id
     */
    public static function pre_post_update($post_id)
    {
        if (isset($_POST['_visibility'])) {
            if (update_post_meta($post_id, '_visibility', wc_clean($_POST['_visibility']))) {
                do_action('woocommerce_product_set_visibility', $post_id, wc_clean($_POST['_visibility']));
            }
        }
        if (isset($_POST['_stock_status'])) {
            wc_update_product_stock_status($post_id, wc_clean($_POST['_stock_status']));
        }
    }
}
WC_Post_Data::init();