Skip to content

Instantly share code, notes, and snippets.

View garousiamir's full-sized avatar
🏠
Working from home

Amirhossein Garousi garousiamir

🏠
Working from home
View GitHub Profile
@garousiamir
garousiamir / rest_api_add_data.php
Created August 22, 2024 18:22
How to add woocommerce custom data to rest api
<?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']);
@garousiamir
garousiamir / get_posts_using_rest.php
Created January 4, 2024 06:51
getting 10 latest wp posts using rest api
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
@garousiamir
garousiamir / user_register_custom_field.php
Created January 3, 2024 16:01
add billing_phone to add new user page of wordpress
// 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 />
@garousiamir
garousiamir / bulk_allow_backorders_for_woocommerce_products.php
Created December 31, 2023 09:21
bulk allow backorders for woocommerce products
<?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);