Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am alexminza on github.
  • I am alexminza (https://keybase.io/alexminza) on keybase.
  • I have a public key whose fingerprint is 4141 875C EAF5 42FF E633 4CB1 3EA4 3664 4C4F 5C80

To claim this, I am signing this object:

@alexminza
alexminza / shortcode_get_option.php
Last active February 27, 2018 11:34
WooCommerce get_option shortcode - Shortcodes, Actions and Filters plugin
//https://codex.wordpress.org/Function_Reference/shortcode_atts
$args = shortcode_atts(
array(
'option' => '',
'default' => '',
), $atts, 'get_option');
//https://developer.wordpress.org/reference/functions/get_option/
return get_option($args['option'], $args['default']);
@alexminza
alexminza / shortcode_product_url.php
Last active February 5, 2018 18:36
WooCommerce product_url shortcode - Shortcodes, Actions and Filters plugin
//https://stackoverflow.com/questions/30539549/woocommerce-product-link-url-for-simple-products
if(empty($atts)) {
return '';
}
if(isset($atts['id'])) {
$product_data = get_post($atts['id']);
} elseif(isset($atts['sku'])) {
$product_id = wc_get_product_id_by_sku($atts['sku']);
@alexminza
alexminza / woocommerce_get_country_locale_romania.php
Created February 5, 2018 18:27
WooCommerce woocommerce_get_country_locale filter - state selection required for Romania
add_filter('woocommerce_get_country_locale', 'woocommerce_get_country_locale_romania');
function woocommerce_get_country_locale_romania($countries) {
//https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-countries.php
$countries['RO']['state']['required'] = true;
}
@alexminza
alexminza / shortcode_attribute_url.php
Created February 5, 2018 18:36
WooCommerce attribute_url shortcode - Shortcodes, Actions and Filters plugin
if(empty($atts)) {
return '';
}
$slug = $atts['slug'];
$taxonomy = $atts['taxonomy'];
$term_link = get_term_link($slug, $taxonomy);
if(is_wp_error($term_link)) {
@alexminza
alexminza / add_rss_featured_image.php
Created February 8, 2018 21:28
WooCommerce rss2_item action - add blog posts featured images to RSS feed
@alexminza
alexminza / woocommerce_ga_snippet_output_userid.php
Last active December 28, 2023 02:15
WooCommerce Google Analytics Integration - add UserID tracking
<?php
//https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/master/includes/class-wc-google-analytics-js.php
function woocommerce_ga_snippet_output_userid($code) {
$user_id = get_current_user_id();
if($user_id > 0) {
$ga_user_id = WC_Google_Analytics_JS::tracker_var() . "('set', 'userId', '" . $user_id . "');";
$code = $code . $ga_user_id;
}
@alexminza
alexminza / wordpress_locale_switch.php
Created February 27, 2018 11:10
WordPress locale language switch
<?php
function set_locale($lang) {
define('LANG_PARAM', 'lang');
$req_lang = $lang;
if(!isset($_SESSION))
session_start();
if(isset($_REQUEST[LANG_PARAM])) {
@alexminza
alexminza / do_shortcode_title.php
Created February 27, 2018 11:31
WordPress shortcodes in titles
<?php
function do_shortcode_title($title) {
return do_shortcode($title);
}
add_filter('the_title', 'do_shortcode_title');
add_filter('single_post_title', 'do_shortcode_title');
@alexminza
alexminza / translate__.php
Created February 27, 2018 11:33
WordPress translate__ shortcode
<?php
//https://codex.wordpress.org/Function_Reference/shortcode_atts
$args = shortcode_atts(
array(
'text' => '',
'domain' => 'default',
), $atts, 'translate__');
//https://developer.wordpress.org/reference/functions/__/
return __($args['text'], $args['domain']);