Skip to content

Instantly share code, notes, and snippets.

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

Mohammed Saimon saimonh3

🏠
Working from home
View GitHub Profile
@saimonh3
saimonh3 / refresh-media-library.js
Created July 30, 2021 20:09
Refresh the WP media library on image upload.
/**
* Refresh the media library on image upload.
* So, it doesn't show previously uploaded images on new uploads
*/
export const refreshMediaLibrary = () => {
wp?.media?.frame?.content?.get?.()?.collection?.props?.set?.( { ignore: ( +new Date() ) } );
};
@saimonh3
saimonh3 / store.php
Created May 20, 2020 07:01
store.php
<?php
/**
* The Template for displaying all single posts.
*
* @package dokan
* @package dokan - 2014 1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@saimonh3
saimonh3 / dokan_get_product_attributes_by_order.php
Created November 18, 2019 07:24
Dokan export order attributes
<?php
/**
* Dokan get seller amount from order total
*
* @param int $order_id
*
* @return float
*/
function dokan_get_seller_amount_from_order( $order_id, $get_array = false ) {
@saimonh3
saimonh3 / class_dokan_update_2_9_21_variation_product_vendor.php
Created October 16, 2019 04:18
class_dokan_update_2_9_21_variation_product_vendor.hp
<?php
defined( 'ABSPATH' ) || exit;
/**
* Dokan 2.9.4 updater class
*
* @since 2.9.4
*/
class Dokan_Update_2_9_21_Variation_Product_Vendor extends Abstract_Dokan_Background_Processes {
@saimonh3
saimonh3 / class_dokan_update_2_9_21_variation_product_vendor.php
Created October 16, 2019 04:18
dokan_update_2_9_21_variation_product_vendor.hp
<?php
defined( 'ABSPATH' ) || exit;
/**
* Dokan 2.9.4 updater class
*
* @since 2.9.4
*/
class Dokan_Update_2_9_21_Variation_Product_Vendor extends Abstract_Dokan_Background_Processes {
@saimonh3
saimonh3 / dokan-upgrade-2.9.21.php
Created October 16, 2019 04:17
dokan-upgrade-2.9.21.php
<?php
/**
* Update post_author id for shop_orders
*
* @since 2.9.4
*
* @return void
*/
function dokan_update_variation_product_vendor() {
@saimonh3
saimonh3 / stripe.php
Created September 22, 2019 03:29
Test Subscription
if ( 'invoice.payment_succeeded' == $event->type ) {
$user_id = $wpdb->get_var( "SELECT `user_id` FROM $wpdb->usermeta WHERE `meta_key` = '_stripe_subscription_id' AND `meta_value`='$invoice->subscription'" );
$period_start = date( 'Y-m-d H:i:s', $invoice->period_start );
$period_end = date( 'Y-m-d H:i:s', $invoice->period_end );
$order_id = get_user_meta( $user_id, 'product_order_id', true );
if ( $invoice->paid ) {
update_user_meta( $user_id, 'product_pack_startdate', $period_start );
update_user_meta( $user_id, 'product_pack_enddate', $period_end );
update_user_meta( $user_id, 'can_post_product', '1' );
@saimonh3
saimonh3 / .zshrc
Created May 15, 2019 12:17 — forked from SumonMSelim/.zshrc
My Terminal Configuration (oh-my-zsh+iTerm2)
# Path to your oh-my-zsh installation.
export ZSH=/Users/SumonMSelim/.oh-my-zsh
# Set name of the theme to load.
ZSH_THEME="powerlevel9k/powerlevel9k"
POWERLEVEL9K_MODE="awesome-fontconfig"
# User configuration
export TERM="xterm-256color"
export SHELL="/bin/zsh"
@saimonh3
saimonh3 / class-wc-query.php
Last active May 6, 2019 21:38
Sort product by popularity with price greater than zero
add_action( 'woocommerce_product_query', function( $qeury ) {
if ( empty( $qeury->query_vars['orderby'] ) || 'popularity' !== $qeury->query_vars['orderby'] ) {
return;
}
add_filter( 'posts_clauses', function( $args ) {
$args['orderby'] = ' CASE wc_product_meta_lookup.min_price WHEN 0 THEN 1
ELSE -1
END ASC, wc_product_meta_lookup.total_sales DESC, wc_product_meta_lookup.product_id DESC
';
function dokan_store_category_menu( $seller_id, $title = '' ) {
?>
<div id="cat-drop-stack">
<?php
$vendor = dokan()->vendor->get( get_query_var( 'author' ) );
$vendor_id = $vendor->get_id();
$products = $vendor->get_products();
$product_ids = [];
foreach ( $products->posts as $product ) {