Skip to content

Instantly share code, notes, and snippets.

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

Nick Mkrtchyan NickMkrtchyan

🏠
Working from home
  • WeBuild Holding LLC
  • Russia / St. Petersburg
View GitHub Profile
@NickMkrtchyan
NickMkrtchyan / wordpress-upload-base64.php
Created January 15, 2024 02:11 — forked from cyberwani/wordpress-upload-base64.php
Upload a base64 string as image to the WordPress media library
<?php
/**
* Save the image on the server.
*/
function save_image( $base64_img, $title ) {
// Upload dir.
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
@NickMkrtchyan
NickMkrtchyan / gist:bbd3f05d233dff84484cd09260be0475
Created February 14, 2023 21:53
Complate Corporate/Customer Woo Script
<?php
// Custom registration form for WooCommerce
function custom_woocommerce_register_form() {
$user_role = ( ! empty( $_POST['user_role'] ) ) ? sanitize_text_field( $_POST['user_role'] ) : '';
$company_id = ( ! empty( $_POST['company_id'] ) ) ? sanitize_text_field( $_POST['company_id'] ) : '';
?>
<p class="form-row form-row-wide">
<label for="user_role"><?php _e( 'Choose account type', 'woodmart' ); ?></label>
<?php
add_action( 'wp_enqueue_scripts', 'liquid_child_theme_style', 99 );
function liquid_parent_theme_scripts() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
function liquid_child_theme_style(){
wp_enqueue_style( 'child-hub-style', get_stylesheet_directory_uri() . '/style.css' );
<?php
/**
* Plugin Name: Custom Payment Gateway
* Plugin URI:
* Description: Woocommerce non_responsible custom payment gateway, for online ordering without online payment systems.
* Author: Nick Mkrtchyan
* Author URI: https://nickmkrtchyan.github.io/
* Version: 1.1.0
* Text Domain: woo_gateway
* Domain Path: /i18n/languages/
@NickMkrtchyan
NickMkrtchyan / woo_shipping_zone_description.php
Created June 7, 2022 10:33
Add shipping method description from Shipping Zones backend, ant print it under chosen shipping method in front.
//
/**
* Check if WooCommerce is active
**/
function smdfw_is_woocommerce_activated() {
return class_exists( 'woocommerce' );
}
/**
* Init plugin
@NickMkrtchyan
NickMkrtchyan / woo_checkout_field_edit.php
Created May 28, 2022 13:28
Woocommerce Checkout Field Editor Snippet
// Woocommerce checkout Fields editor
add_filter( 'woocommerce_checkout_fields', 'woo_checkout_field_editor' );
function woo_checkout_field_editor( $fields ) {
unset( $fields['billing']['billing_first_name'] );
unset( $fields['billing']['billing_last_name'] );
unset( $fields['billing']['billing_country'] );
unset( $fields['billing']['billing_email'] );
unset( $fields['billing']['billing_phone'] );
// unset( $fields['billing']['billing_company'] );
@NickMkrtchyan
NickMkrtchyan / woo_registration_user_role_select.php
Last active May 28, 2022 13:08
Adding role selection during registration
/**
* @snippet WooCommerce Role Select During Registration
* @how-to https://woohacks.github.io/
* @author Nick Mkrtchyan
* @compatible WooCommerce 5.0
*/
function register_role_select_option() {
global $wp_roles; ?>
<p class="form-row form-row-wide">
<label for="reg_billing_phone"><?php echo __( 'Student or Instructor', 'woocommerce' ) ?></label>
@NickMkrtchyan
NickMkrtchyan / woo_rename_customer_role.php
Created May 20, 2022 14:46
Snippet for rename default WordPress / WooCommerce role name
/**
* @snippet WooCommerce Rename Customer Role Name
* @how-to https://woohacks.github.io/
* @author Nick Mkrtchyan
* @compatible WooCommerce 5.0
*/
function change_role_name() {
global $wp_roles;
if ( ! isset( $wp_roles ) )
$wp_roles = new WP_Roles();