Skip to content

Instantly share code, notes, and snippets.

View pietromalerba's full-sized avatar

Pietro Malerba pietromalerba

  • M3
  • Civitanova Marche (MC) - Italy
View GitHub Profile
<?php
class MyJS {
public function __construct() {
add_action( 'wp_enqueue_scripts', array( &$this, 'addScripts' ) );
}
public function addScripts() {
// jQuery
@pietromalerba
pietromalerba / functions.php
Last active August 29, 2015 14:08 — forked from kloon/functions.php
Woocommerce filter price
<?php
// Add save percent next to sale item prices.
add_filter( 'woocommerce_sale_price_html', 'woocommerce_custom_sales_price', 10, 2 );
function woocommerce_custom_sales_price( $price, $product ) {
$percentage = round( ( ( $product->regular_price - $product->sale_price ) / $product->regular_price ) * 100 );
return $price . sprintf( __(' Save %s', 'woocommerce' ), $percentage . '%' );
}
?>
<?php
global $wpdb;
// Insert the original post
$original = wp_insert_post($array, true);
// Insert the translated post
$translated = wp_insert_post($array, true);
// Make some updates to both translations
<?php
/**
* Add the custom attribute "Special Promotion" to a product.
*/
add_filter( 'dfrpswc_product_attributes', 'mycode_add_promo_attribute', 20, 5 );
function mycode_add_promo_attribute( $attributes, $post, $product, $set, $action ) {
if ( isset( $product['promo'] ) ) {
$attr = 'Special Promotion';
if ( !isset( $attributes[sanitize_title( $attr )] ) ) {
<?php
/**
* Add color attribute.
*
* The attribute "Color" with a slug of "color" must already exist here:
* WordPress Admin Area > Products > Attributes.
*/
add_filter( 'dfrpswc_filter_attribute_value', 'mycode_add_color_attribute', 20, 6 );
function mycode_add_color_attribute( $value, $attribute, $post, $product, $set, $action ) {
@pietromalerba
pietromalerba / wordpress-adminbar-modal.php
Last active June 30, 2019 00:53 — forked from MrMaz/ab-modal.php
Wordpress admin bar modal box
<?php
/**
* Setup admin bar item which opens URL in a thickbox window
*
* @param WP_Admin_Bar $wp_admin_bar
*/
function admin_bar_menu_modal_window( $wp_admin_bar )
{
// add "tools" node
@pietromalerba
pietromalerba / woocommerce-my-account.php
Last active July 13, 2022 18:34 — forked from SirDarcanos/functions.php
Add custom fields to Woocommerce My Account
// Add VAT and SSN fields in billing address display
add_filter( 'woocommerce_order_formatted_billing_address', 'custom_add_vat_ssn_formatted_billing_address', 10, 2 );
function custom_add_vat_ssn_formatted_billing_address( $fields, $order ) {
$fields['vat'] = $order->billing_vat;
$fields['ssn'] = $order->billing_ssn;
return $fields;
}
add_filter( 'woocommerce_my_account_my_address_formatted_address', 'custom_my_account_my_address_formatted_address', 10, 3 );
<?php
/*
Plugin Name: Listing Content Item
Plugin URI:
Description:
Author:
Version: 1.0
Author URI:
*/
<?php
/*
Description: Adds a taxonomy filter in the admin list page for a custom post type.
Written for: http://wordpress.stackexchange.com/posts/582/
By: Mike Schinkel - http://mikeschinkel.com/custom-workpress-plugins
Instructions: Put this code in your theme's functions.php file or inside your own plugin. Edit to suite your post types and taxonomies. Hope this helps...
*/
add_filter('manage_listing_posts_columns', 'add_businesses_column_to_listing_list');
function add_businesses_column_to_listing_list( $posts_columns ) {
if (!isset($posts_columns['author'])) {
<?php
// define location of Parse PHP SDK, e.g. location in "Parse" folder
// Defaults to ./Parse/ folder. Add trailing slash
define( 'PARSE_SDK_DIR', './Parse/' );
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
use Parse\ParseClient;