Skip to content

Instantly share code, notes, and snippets.

View lunule's full-sized avatar

lunule lunule

  • Vigilante One
  • Brno
View GitHub Profile
@lunule
lunule / wp_get_all_roles.php
Last active July 31, 2020 06:14
[WordPress - get all (editable) roles] #wordpress #core #wp-core #roles #capabilities
function qsa_get_editable_roles() {
global $wp_roles;
$all_roles = $wp_roles->roles;
$editable_roles = apply_filters('editable_roles', $all_roles);
// var_dump($editable_roles);
}
@lunule
lunule / wp_get_all_custom_fields.php
Last active July 31, 2020 06:13
[WordPress - get/dump all custom fields] #wp #wp-core #wordpress #custom-fields #var_dump
<?php
// @see https://css-tricks.com/snippets/wordpress/dump-all-custom-fields/
?>
<h3>All Post Meta</h3>
<?php $getPostCustom = get_post_custom(); // Get all the data ?>
<?php
foreach( $getPostCustom as $name => $value ) :
@lunule
lunule / wp_display_all_visible_and_hidden_custom_fields_for_current_post.php
Last active July 31, 2020 06:13
[WordPress - Access All Visible and Hidden Post Meta for the Current Post] #wp #wordpress #wp-core #custom-fields #post-meta #hidden
<?php
/**
* Display all post meta, including hidden/protected meta, for the current post
* @author Ren Ventura <EngageWP.com>
*
* @see https://www.engagewp.com/access-visible-hidden-post-meta-current-post/
*/
add_action( 'wp_head', 'rv_output_all_post_meta' );
function rv_output_all_post_meta() {
@lunule
lunule / wc_get_user_id_from_order.php
Last active July 31, 2020 06:13
[WooCommerce - get user id from/belonging to an order] #woocommerce #wc #order #user_id #user
function qsa_purchase_success_callback( $order_id ) {
$order = wc_get_order( $order_id );
$user = $order->get_user();
$uid = $order->get_user_id();
qsa_update_user_meta($uid);
}
@lunule
lunule / wp_save_shit_on_user_profile_update.php
Last active July 31, 2020 06:13
[WordPress - save shit when a user profile is/gets updated] #wordpress #wp #wp-core #user #profile
function qsa_save_user_profile_callback( $user_id ) {
qsa_update_user_meta($user_id);
}
add_action( 'profile_update', 'qsa_save_user_profile_callback', 10, 2 );
/**
* FYKI: the below hooks should work, theoretically - only they don't. :(
*/
@lunule
lunule / wc_save_shit_on_purchase_success.php
Last active July 31, 2020 06:12
[WooCommerce - save shit on successful purchase] (when order date is required) #woocommerce #wc #wc-hooks #hooks #actions
function qsa_purchase_success_callback( $order_id ) {
$order = wc_get_order( $order_id );
$user = $order->get_user();
$cid = $order->get_user_id();
qsa_update_user_meta($cid);
}
@lunule
lunule / wc_override_woocommerce_templates_from_plugin.php
Last active February 17, 2021 15:24
[WooCommerce - How to override templates using a custom functionality plugin] #woocommerce #override #overwrite #templates #plugin #filter #hook
<?php
/**
* There seem to be two versions.
*
* Version 1 - if it works as expected, use this one!!!
* @see https://wpdevdesign.com/how-to-override-woocommerce-templates-using-a-custom-functionality-plugin/
*
* Version 2
* @see https://wisdmlabs.com/blog/override-woocommerce-templates-plugin/
@lunule
lunule / wc_change_add_to_cart_button_text.php
Created February 17, 2021 15:20
[WooCommerce: How to change “Add to cart” button text?] #woocommerce #filter #hook #add-to-cart #cart
<?php
/**
* @see https://www.codegearthemes.com/blogs/woocommerce/woocommerce-how-to-change-add-to-cart-button-text
*/
// To change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_custom_single_add_to_cart_text' );
function woocommerce_custom_single_add_to_cart_text() {
return __( 'Buy Now', 'woocommerce' );
@lunule
lunule / wc_get_product_download_url.php
Created February 17, 2021 15:23
[WooCommerce - Get Product Download Url] FYKI: there might be multiple downloads, so we need looping #woocommerce #product #url #download
<?php
$downloads = $product->get_files();
foreach( $downloads as $key => $download ) :
echo '<p class="download-link"><a href="' . esc_url( $download['file'] ) . '">' . $download['name'] . '</a></p>';
endforeach;
@lunule
lunule / wp_list_post_types.php
Last active April 11, 2021 19:06
[WP - List Post Types] #post-types #wordpress #wp #core
<?php
function keto_list_post_types() {
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'names'; // 'names' or 'objects' (default: 'names')