Skip to content

Instantly share code, notes, and snippets.

View amirhp-com's full-sized avatar
🔥

Amirhossein Hosseinpour amirhp-com

🔥
View GitHub Profile
@amirhp-com
amirhp-com / index.js
Created September 17, 2024 00:52
Directly Open Print Dialog for a PDF from URL
/*
* Directly Open Print Dialog for a PDF from URL
* Developer: Amirhp.com
* Contact: its@amirhp.com
*
* 1. add following iframe and load pdf into it:
* 2. <iframe id="print_pdf_iframe" src="https://site.com/sample.pdf" frameborder="0"></iframe>
* 3. Then for print button, add print_pdf function as command
*/
@amirhp-com
amirhp-com / index.php
Last active September 17, 2024 00:32
Generate a Vertical barcode using Picqer/Barcode and Help of PeproDev Ultimate Invoice for mPDF
<?php
// Generate a Vertical barcode using Picqer/Barcode and Help of PeproDev Ultimate Invoice for mPDF
try {
global $PeproUltimateInvoice;
$generator = $PeproUltimateInvoice->barcode;
$barcode_text = "123456789";
$barcode = 'data:image/jpeg;base64,' . base64_encode($generator->getBarcode($barcode_text, $generator::TYPE_CODE_128));;
echo "<img src='$barcode' rotate='90' style='width:30px; height:100px; margin: 8px 0 4px;'>";
} catch (\Throwable $th) {
//throw $th;
@amirhp-com
amirhp-com / fix-wc-orders-screen.php
Created July 27, 2024 20:46
Fix WooCommerce Order Screen responsive problem to show full order's details.
<?php
/*
Fix WooCommerce Order Screen responsive problem to show full order's details.
Snippet by Amirhp.Com - Tested on WC 9.1.2 & WP 6.6.1
*/
add_action("manage_shop_order_posts_custom_column", "wc_fix_render_column", 10, 2 );
add_action("manage_woocommerce_page_wc-orders_custom_column", "wc_fix_render_column", 10, 2 );
add_action("admin_enqueue_scripts", "wc_fix_admin_styles");
@amirhp-com
amirhp-com / flywheel-local-xdebug-vscode.md
Created December 17, 2022 09:33 — forked from Niq1982/flywheel-local-xdebug-vscode.md
WordPress debugging with XDebug on Flywheel Local & VSCode

Flywheel Local configuration

Flywheel Local has XDebug installed by default if you choose “Custom” instead of “Preferred” when setting up a new local environment. If you don’t know which your current site is running, you can detect it by going to ”Site Setup” tab. If you can change the PHP version there, you have the “Custom” environment running. If not, just export your site, import it back and choose “Custom”.

Now that we have the right environment, remember what PHP version you are running, open the right PHP settings file (for example /Local Sites/my_site/conf/php/7.0.3/php.ini) and add these lines in the [Xdebug] section:

xdebug.remote_enable=1
xdebug.remote_autostart=1

Save the php.ini and restart your site container in Flywheel to apply new settings.

@amirhp-com
amirhp-com / atom-copy-filename.md
Last active August 15, 2022 07:46 — forked from piascikj/atom-copy-filename.md
Atom copy filename

Use CTRL-SHIFT-A to Copy current filename to clipboard or CTRL-SHFIT-X to insert file name at current position.

Add following code on ~/.atom/keymap.cson
'atom-text-editor':
  'ctrl-shift-a': 'amirhp-com:copy-file-name'
  'ctrl-shift-x': 'amirhp-com:insert-file-name'
Add following code on ~/.atom/init.coffee
@amirhp-com
amirhp-com / snippet-amirhp-com.php
Last active August 15, 2022 10:25
WooCommerce move Out-of-stock Products and Products with zero or empty price to end of list
<?php
# @Author: amirhp-com
# @Date: 2022/07/25 05:53:08
# @Email: its@amirhp.com
// order by lowest price to highest
add_filter("woocommerce_default_catalog_orderby", function( $sort_by ){ return 'price';} );
// order zero-price products last, followed by out-of-stock products
@amirhp-com
amirhp-com / Arabic character to Persian (Farsi) - PHP
Created July 15, 2022 10:59 — forked from amirasaran/Arabic character to Persian (Farsi) - PHP
convert Arabic character to Persian (Farsi) - PHP
<?php
public static function arabicToPersian($string)
{
$characters = [
'ك' => 'ک',
'دِ' => 'د',
'بِ' => 'ب',
'زِ' => 'ز',
'ذِ' => 'ذ',
'شِ' => 'ش',
<?php
add_filter( "puiw_printinvoice_create_html_item_row_metas", "my_custom_lineitems_macros", 10, 5);
/* add the macro: {{{remaining-qty}}} */
function my_custom_lineitems_macros ($macros, $item_id, $item, $product_id, $order){
$product = $item->get_product();
$current_qty = $product->get_stock_quantity();
$bought_qty = $item->get_quantity();
$remaining_qty = (int) $current_qty - (int) $bought_qty;
$macros["remaining-qty"] = $remaining_qty;
<?php
$args = array(
'label' => '', // Text in Label
'class' => '',
'style' => '',
'wrapper_class' => '',
'value' => '', // if empty, retrieved from post meta where id is the meta_key
'id' => '', // required
'name' => '', //name will set from id if empty