This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class KavehRestRules | |
| { | |
| public function __construct() | |
| { | |
| add_action('rest_api_init', [$this, 'kaveh_rest_posts']); | |
| if (class_exists('woocommerce')) { | |
| add_action('rest_api_init', [$this, 'kaveh_rest_products']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action('init','show_posts_rest'); | |
| function show_posts_rest(){ | |
| // Create a request to the WordPress REST API to get the latest 10 posts | |
| $request = new WP_REST_Request('GET', '/wp/v2/posts'); | |
| $request->set_query_params(array( | |
| 'per_page' => 10, // Number of posts to retrieve | |
| 'orderby' => 'date', // Order by date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add a new field for billing phone in the user profile | |
| function custom_user_profile_fields($user) { | |
| ?> | |
| <table class="form-table"> | |
| <tr> | |
| <th><label for="billing_phone"><?php esc_html_e('شماره موبایل', 'text-domain'); ?></label></th> | |
| <td> | |
| <input type="text" name="billing_phone" id="billing_phone" value="<?php echo esc_attr(get_user_meta($user->ID, 'billing_phone', true)); ?>" class="regular-text" /><br /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function run_this_once() { | |
| // Check if the function has already been executed | |
| if ( ! get_option( 'my_function_executed' ) ) { | |
| $args = array( | |
| 'post_type' => 'product', // WooCommerce product post type | |
| 'posts_per_page' => -1, // Number of products to display (-1 to display all) | |
| ); | |
| $products = new WP_Query($args); |