Skip to content

Instantly share code, notes, and snippets.

View KeylorCR's full-sized avatar

Keylor Mendoza KeylorCR

View GitHub Profile
@KeylorCR
KeylorCR / archive-store.php
Created April 5, 2021 23:39
Archive template for store CPT using the stores ordering configurations from WC Pickup Store settings page.
<?php
/**
** The template for displaying archive store post type
** Current version: 1.5.13
**/
get_header(); ?>
<div id="primary" class="content-area">
<header class="entry-header">
<h1 class="wps-title page-title"><?= post_type_archive_title() ?></h1>
<?php
/**
* Change shipping method priority
* Use array_unshift for the beginnig and array_push onto the end of array
*/
function kmchild_sort_shipping_methods($available_shipping_methods, $package) {
if (isset($available_shipping_methods['wc_pickup_store'])) {
$wc_pickup_store = $available_shipping_methods['wc_pickup_store'];
unset($available_shipping_methods['wc_pickup_store']);
// array_unshift($available_shipping_methods, $wc_pickup_store); // Prepend element to the beginning of array
@KeylorCR
KeylorCR / wcpcd-functions.php
Last active March 15, 2022 15:55
Custom filters and functions for plugin WC Provincia-Cantón-Distrito
<?php
/**
* Adding custom json locations from child theme
* WC Provincia-Canton-Distrito
*/
function kmchild_prov_cant_dist_json($json_file) {
$json_file = get_stylesheet_directory_uri() . '/assets/js/prov-cant-dist.json';
return $json_file;
}
@KeylorCR
KeylorCR / wps-filterts.php
Last active February 28, 2024 05:22
List of filters included in the WC Pickup Store plugin. Check for filter availability in the plugin source code.
<?php
/**
* Add new content to be displayed in the template of store information in the Checkout page
*
* @author: @keylorcr
* @version 1.5.23
*/
function kmchild_wps_stores_fields($the_fields) {
foreach ($the_fields as $store_id => $value) {
$the_fields[$store_id][] = array(
<?php
/**
** Add extra information to admin order actions column
** @keylocr - 29-01-2020
**/
function wc_custom_admin_order_actions_end($object) {
$order_id = $object->get_id();
$store = (!empty(get_post_meta($order_id, '_shipping_pickup_stores', true))) ? get_post_meta($order_id, '_shipping_pickup_stores', true) : '';
if(!empty($store)) :
@KeylorCR
KeylorCR / wc-remove-address-pickup-store.php
Last active January 29, 2020 06:35
Remove woocommerce email addresses on wc_pickup_store shipping method
<?php
function wc_removing_customer_details_in_emails($order, $sent_to_admin, $plain_text, $email) {
if ($order->has_shipping_method('wc_pickup_store')) {
$mailer = WC()->mailer();
remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20, 3 );
}
}
add_action('woocommerce_email_customer_details', 'wc_removing_customer_details_in_emails', 5, 4);
/**
** After update checkout
**/
$(document.body).on('update_checkout, updated_checkout', function () {
validate_checkout_required_fields();
});
function validate_checkout_required_fields() {
if($('select.shipping_method').val() == "wc_pickup_store") {
$('#billing_state_field, #billing_city_field, #billing_address_1_field').find(".required").hide();
@KeylorCR
KeylorCR / wc-custom-functions.php
Created June 11, 2019 23:48
Adding superscript to wc_price filter <sup></sup>. Working to all prices throughout the site.
<?php
/**
** Adding superscript to wc_price <sup></sup>
** not working with prices into select2
**/
function custom_custom_price_format($return, $price, $args, $unformatted_price) {
$elements = explode('.', $price);
if(is_admin()) {
return $return;
@KeylorCR
KeylorCR / wps-get-custom-data.php
Last active August 1, 2022 03:30
These snippets allow you to get custom fields data from stores and show them in the order email or in the order item totals that appears on several parts of the WC site
<?php
/**
** Get the store details and add them to order email
** below the order table
** WC Pickup Store plugin
** https://wordpress.org/plugins/wc-pickup-store/
**/
function custom_order_details_after_order_table($order) {
$order_id = $order->get_id();
$store_name = get_post_meta($order_id, '_shipping_pickup_stores', true); // Get store title for this order
@KeylorCR
KeylorCR / 0_reuse_code.js
Created August 30, 2017 03:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console