Skip to content

Instantly share code, notes, and snippets.

View hamidrezayazdani's full-sized avatar
🤕

Hamid Reza Yazdani hamidrezayazdani

🤕
View GitHub Profile
<?php
/**
* Change "Add to cart" button text
*/
add_filter( 'woocommerce_product_single_add_to_cart_text', 'ywp_override_add_to_cart_text', PHP_MAX_INT );
add_filter( 'woocommerce_product_add_to_cart_text', 'ywp_override_add_to_cart_text', PHP_MAX_INT );
function ywp_override_add_to_cart_text() {
return 'ثبت سفارش';
}
<?php
/**
* add shortcode to wp
*/
add_shortcode( 'stock_status', 'display_product_stock_status' );
function display_product_stock_status( $atts) {
$atts = shortcode_atts(
array('id' => get_the_ID() ),
$atts,
@hamidrezayazdani
hamidrezayazdani / add-custom-field-to-wc-register-form.php
Last active June 22, 2021 08:26
Add first & last name fields to woocommerce registration form
<?
/**
* Add a custom field to woocommerce registeration form
*/
add_action( 'woocommerce_register_form', 'ywp_add_name_field_ro_wc_register_form' );
function ywp_add_name_field_ro_wc_register_form() {
woocommerce_form_field(
'ywp_register_fname',
array(
'type' => 'text',
@hamidrezayazdani
hamidrezayazdani / show-visual-editor-in-admin-taxonomies-pages.php
Last active May 24, 2024 07:17
Activate the visual editor in admin taxonomies pages
<?php
$taxonomies = array(
'category', // for posts categories
'post_tag', // for posts tags
'product_tag', // for wc products tags
'product_cat', // for wc products categories
'product_brand', // for woocommerce brand plugin
'brand', // for yith product brand
@hamidrezayazdani
hamidrezayazdani / replace_persian_arabic_numbers_in_metadata.php
Created August 1, 2021 21:16
This snippet convert persian/arabic numbers to english numbers in metadata
<?php
/**
* Convert numbers to english
*
* @param $input
*
* @return array|string
*/
function ywp_convert_numbers_to_latin( $input ): array|string {
$arabic = [ '٩', '٨', '٧', '٦', '٥', '٤', '٣', '٢', '١', '٠' ];
<?php
/**
* Add custom endpoint to the My Account menu
*
* @param array $items
*
* @return array
*/
function ywp_account_menu_custom_item( $items ) {
$logout = $items['customer-logout'];
@hamidrezayazdani
hamidrezayazdani / convert-all-price-from-Rial-to-Toman.sql
Last active September 1, 2021 13:43
تبدیل قیمت کلیه محصولات ووکامرس از ریال به تومان
-- توجه: حتما قبل از اجرای این کد، از دیتابیس نسخۀ پشتیبان تهیه کنید --
-- وارد فضای هاست خود شده و PHPMyAdmin را باز کرده و کد زیر را در بخش SQL اجرا کنید. --
-- تبدیل قیمت همه محصولات به تومان --
UPDATE
wp_postmeta
SET
@hamidrezayazdani
hamidrezayazdani / add-custom-bulk-action-to-wc-orders.php
Created September 18, 2021 09:21
افزودن «کارهای دسته جمعی» به سفارشات ووکامرس
<?php
/**
* Add packaging option to order bulk actions
*/
function ywp_add_packaging_to_bulk_actions( $actions ) {
$actions['mark_packaging'] = 'تغییر وضعیت به بسته‌بندی';
return $actions;
}
@hamidrezayazdani
hamidrezayazdani / get-order-shipping-method-details.php
Created September 20, 2021 20:38
دریافت اطلاعات «روش‌های ارسال» سفارش خاص
<?php
$order = wc_get_order( $order_id );
$order_shipping_methods = $order->get_items( 'shipping' );
foreach ( order_shipping_methods as $item_id => $item ) {
$shipping_method_instance_id = $item->get_instance_id();
$shipping_method_id = $item->get_method_id();
$shipping_method_title = $item->get_method_title();
$order_item_name = $item->get_name();
@hamidrezayazdani
hamidrezayazdani / wc-latest-modified-products-shortcode.php
Created September 28, 2021 16:47
کد کوتاه نمایش محصولات بر اساس تاریخ آخرین ویرایش در ووکامرس
<?php
function ywp_date_modified_wc_product_shortcode( $args, $atts ){
$atts = shortcode_atts(
array(
'orderby' => 'date',
'interval' => '20',
), $atts, 'bartag'
);
if ( 'date_modified' === esc_attr( $atts['orderby'] ) ) {