Skip to content

Instantly share code, notes, and snippets.

View Preciousomonze's full-sized avatar
🤡
Coding on the bicycle 😎🚴🏽‍♂️

Precious Omonzejele Preciousomonze

🤡
Coding on the bicycle 😎🚴🏽‍♂️
View GitHub Profile
@Preciousomonze
Preciousomonze / Frontend.min.js
Last active October 1, 2020 15:33
Phone Validator for WooCommerce JS temporary fix for v1.3.0 and below. (Please you should always update to the latest versions 😬) See the instruction readme: https://gist.github.com/Preciousomonze/e1f276a525e2bcd3f38de475cd5f62bf/#file-phone-validator-1-3-0-info-fix-md
var $=jQuery,wcPvPhoneErrorMap=wcPvJson.validationErrors;0==$('.wc-pv-intl input').length&&$('#billing_phone_field').addClass('wc-pv-phone wc-pv-intl');var wcPvDefCountry=''==wcPvJson.defaultCountry?$(`${wcPvJson.parentPage} #billing_country`).val():wcPvJson.defaultCountry;let separateDialCode=1==wcPvJson.separateDialCode,onlyCountries=wcPvJson.onlyCountries.map(e=>e.toUpperCase());var wcPvPhoneIntl=$('.wc-pv-intl input').intlTelInput({initialCountry:''==wcPvDefCountry||'default'==wcPvDefCountry||void 0==wcPvDefCountry?'NG':wcPvDefCountry,onlyCountries:onlyCountries,separateDialCode:separateDialCode,preferredCountries:wcPvJson.preferredCountries,utilsScript:wcPvJson.utilsScript}),wcPvphoneErrMsg='';function wcPvValidatePhone(e){const n=e;let o=!1;if(1==n.intlTelInput('isValidNumber'))o=n.intlTelInput('getNumber');else{let e=n.intlTelInput('getValidationError');wcPvphoneErrMsg=`${wcPvJson.phoneErrorTitle+(void 0==wcPvPhoneErrorMap[e]?wcPvJson.phoneUnknownErrorMsg:wcPvPhoneErrorMap[e])}`;}return o;}function wcP
@Preciousomonze
Preciousomonze / pekky_csv_reader_for_images.php
Created October 5, 2020 19:30
WooCommerce Product Importer Image sort helper.
<?php
/**
* WooCommerce Product Importer Image sort helper.
*
* Wrote this code around last year, tired and rushing :)
* It helps read csv and your images folder and set an absolute path
* For your image column, so you can import your Woocommerce products with it's images Successfully.
* Put this file anywhere with your necessary folder paths, you'll edit in the variables below.
* REQUIRES AT LEAST PHP 5.6 (cause i used that, so higher versions should work :) ).
* Note: Image column number is 28(starting from 0) in a standard WooCommerce Import(hope it hasn't changed by now shaa), which is what i used.
<?php
/*
* This code should be in the proper place of your_child_theme/woocommerce/single-product/product-attributes.php file.
* Hope this helps you, but still, enjoy at your own risk. :)
*/
/**
* Product attributes
*
* Used by list_attributes() in the products class.
@Preciousomonze
Preciousomonze / pekky-catalog-snippet.php
Created October 8, 2020 13:49
Alter WooCommerce Product Catalog visibility via hook. Based on this thread here: https://woocommercecommunity.slack.com/archives/C1KAZ91E3/p1601981478254000
<?php
/**
* Change catalog visibility.
*
* No need to run ::save(), cause this hook is run before $product->save()
*
* Hooked to woocommerce_admin_process_product_object
*
* @param WC_Product $product The product object.
*/
@Preciousomonze
Preciousomonze / code.php
Last active November 11, 2020 15:26
Add a dynamic fee to meet up to your minimum total allowed for your store. This is useful incase you want the user to order from your store, but want a minimum cart total price, and at the same time if the cart total is less than your minimum price, you dynamically add what's left to meet the minimum price: more info here: https://woocommercecom…
/**
* Helps sort extra fee to meet minimum total.
*/
function pekky_sort_extra_fee() {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
$minimum_price = 20; // The minimum price you allow for a user to be able to place order.
@Preciousomonze
Preciousomonze / custom.php
Last active April 14, 2021 13:52
Cache-bust all scripts/styles
<?php
/**
* Cache-bust all scripts/styles. form helgatheviking
*
* Can go to your functions.php.
* Useful for development purposes.
* Special thanks to HelgaTheViking.
*/
function pekky_add_timestamp_css_js( $src ) {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
@Preciousomonze
Preciousomonze / frontend.js
Created July 29, 2021 09:16
Temporary fix: conflict with some themes (JS error - Uncaught SyntaxError) #40: https://https://github.com/Preciousomonze/woocommerce-phone-validator/issues/40
jQuery( document ).ready( function( $ ){
// set phone number properly for intl
// here, the index maps to the error code returned from getValidationError
var wcPvPhoneErrorMap = wcPvJson.validationErrors;
// start
if ($( '.wc-pv-intl input' ).length == 0) {// add class, some checkout plugin has overriden my baby
$( '#billing_phone_field' ).addClass( 'wc-pv-phone wc-pv-intl' );
}
// Set default country.
var wcPvDefCountry = ( wcPvJson.defaultCountry == '' ? $( `${wcPvJson.parentPage} #billing_country` ).val() : wcPvJson.defaultCountry );
@Preciousomonze
Preciousomonze / Readme.md
Last active June 12, 2024 09:15
Paid Membership Pro - How to get some functions you might not see in the documentation. happened to me a lot 😁

So I'll just try to be dumping some things here for docu purposes. Feel free to comment, if you have more to add. I'll try as much as possible to update.

Disclaimer: Please remember that we are all imperfect, and as such, some of the info here might be or outdated or incomplete, that's why we're a community. Any info you find incorrect, please do well to suggest the correct thing in the comment section, we're doing it for all of us. People powerrr

Note: That this also includes functions from their addons.

Format will be "Function name - Plugin name"

pmprorh_getProfileFields - Paid Membership Pro Registration Helper

Guess this helps get the fields from the profile.

@Preciousomonze
Preciousomonze / custom_functions.php
Last active August 8, 2021 18:05
Contact form 7 file upload to pmpro registration helper plugin - usecase is when adding a user via cf7, and a file upload is also supported. I had to readjust my actual code to fit for this example, so it might be rough 🤗. by the way, this stressed me out. hope i could solve your problem.
<?php
/**
* Upload our file to pmpro helper side.
*
* @param array $cf7_uploads
* @return bool false if file isnt set, true otherwise, just vibess.
*/
function pekky_upload_cf7_file_to_pmp_temp( $cf7_uploads ) {
if ( ! is_array( $cf7_uploads ) ) {
@Preciousomonze
Preciousomonze / cross-sells.php
Last active October 26, 2021 11:55
Display cross sells of a particular product in a cart. Add the file to your child theme: 'woocommerce/cart/' folder.
<?php
/**
* Cross-sells
*
* This template can be overridden by copying it to yourtheme/woocommerce/cart/cross-sells.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and