_x( "Discount Manager", "Discount Manager" ), 'name' => _x( "Discount Manager", "Discount Manager" ), 'menu_name' => 'Discount Manager', 'add_new' => _x( "Add New Entry", "Discount Manager" ), 'add_new_item' => __( "Add New" ), 'edit_item' => __( "Edit Entry" ), 'new_item' => __( "New Entry" ), 'view_item' => __( "View Entry" ), 'search_items' => __( "Search Entries" ), 'not_found' => __( "No Entries Found" ), 'not_found_in_trash' => __( "No Entries Found in Trash" ), 'parent_item_colon' => '' ); // Register post type register_post_type( 'sup_discount_manager', array( 'labels' => $labels, 'public' => true, 'menu_position' => 100, 'has_archive' => false, 'hierarchical' => false, 'publicly_queryable' => false, 'menu_icon' => plugins_url( 'icon.png', __FILE__ ), 'capabilities' => array( 'edit_post' => 'update_core', 'read_post' => 'update_core', 'delete_post' => 'update_core', 'edit_posts' => 'update_core', 'edit_others_posts' => 'update_core', 'delete_posts' => 'update_core', 'publish_posts' => 'update_core', 'read_private_posts' => 'update_core' ), 'rewrite' => array( 'slug' => '', 'with_front' => false ), 'supports' => array( 'title' ) ) ); } add_action( 'init', 'supadu_create_discount_manager', 0 ); if( function_exists( 'acf_add_local_field_group' ) ): acf_add_local_field_group( array( 'key' => 'group_578769945f83a', 'title' => 'Discount Manager', 'fields' => array( array( 'key' => 'field_57876cd5fdbed', 'label' => 'Discount Scope', 'name' => 'discount_manager_scope', 'type' => 'select', 'instructions' => '', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'All' => 'All', 'ISBN List' => 'ISBN List', ), 'default_value' => array(), 'allow_null' => 0, 'multiple' => 0, 'ui' => 0, 'ajax' => 0, 'return_format' => 'value', 'placeholder' => '', ), array( 'key' => 'field_57f798e16b2d6', 'label' => 'ISBNs', 'name' => 'discount_manager_isbns', 'type' => 'text', 'instructions' => 'Please enter a comma separated ISBN list', 'required' => 0, 'conditional_logic' => array( array( array( 'field' => 'field_57876cd5fdbed', 'operator' => '==', 'value' => 'ISBN List', ), ), ), 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), array( 'key' => 'field_590841f7ffe4c', 'label' => 'Discount Parameter', 'name' => 'discount_manager_parameter', 'type' => 'text', 'instructions' => '', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), array( 'key' => 'field_590843924682e', 'label' => 'Start Date', 'name' => 'discount_manager_startdate', 'type' => 'date_picker', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'display_format' => 'd/m/Y', 'return_format' => 'd/m/Y', 'first_day' => 1, ), array( 'key' => 'field_59b16a0ffed76', 'label' => 'End Date', 'name' => 'discount_manager_enddate', 'type' => 'date_picker', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'display_format' => 'd/m/Y', 'return_format' => 'd/m/Y', 'first_day' => 1, ), array( 'key' => 'field_590844aee4f69', 'label' => 'Currency', 'name' => 'discount_manager_currency', 'type' => 'select', 'instructions' => '', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'All' => 'All', 'GBP' => 'GBP', 'USD' => 'USD', ), 'default_value' => array(), 'allow_null' => 0, 'multiple' => 0, 'ui' => 0, 'ajax' => 0, 'return_format' => 'value', 'placeholder' => '', ), array( 'key' => 'field_59b2751e77dd5', 'label' => 'Discount Type', 'name' => 'discount_manager_type', 'type' => 'select', 'instructions' => '', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Percentage' => 'Percentage', 'Flat' => 'Flat', 'Other' => 'Other', ), 'default_value' => array(), 'allow_null' => 0, 'multiple' => 0, 'ui' => 0, 'ajax' => 0, 'return_format' => 'value', 'placeholder' => '', ), array( 'key' => 'field_59b275d677dd6', 'label' => 'Discount Value', 'name' => 'discount_manager_value', 'type' => 'number', 'instructions' => 'Please enter a number', 'required' => 1, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'min' => '', 'max' => '', 'step' => '', ), ), 'location' => array( array( array( 'param' => 'post_type', 'operator' => '==', 'value' => 'sup_discount_manager', ), ), ), 'menu_order' => 0, 'position' => 'normal', 'style' => 'default', 'label_placement' => 'top', 'instruction_placement' => 'label', 'hide_on_screen' => '', 'active' => 1, 'description' => '', ) ); endif; /** * @return array */ function supadu_discount_manager_get_discounts() { $discounts = array(); //AT - this needs to be changed to only get discounts that are active or relevant to the book // [3:56 PM] David Kane: you should be doing a WP Query on the meta data for any discounts with the isbn && and discounts with "all" // [3:56 PM] David Kane: or something // [3:56 PM] David Kane: and in date range yes $args = array( 'post_type' => 'sup_discount_manager', ); $my_query = new WP_Query( $args ); if( isset( $my_query->posts ) && count( $my_query->posts ) > 0 ) { foreach( $my_query->posts as $post ) { $tmp = get_post_meta( $post->ID ); foreach( $tmp as $key => $value ) { $tmp[$key] = reset( $value ); } $tmp['discount_manager_title'] = $post->post_title; $postDate = strtotime( $post->post_modified ); $discounts[$postDate] = $tmp; } } return $discounts; } /** * @param $supapress * @param $discounts * @param $returnObject * * @return string */ function supadu_discount_manager_get_discount($supapress, $discounts, $returnObject = false) { $myDiscounts = array(); $myDiscount = ''; if( isset( $supapress ) && !empty( $discounts ) ) { foreach( $discounts as $dateModified => $discount ) { $inDateRange = supadu_discount_manager_date_in_range( $discount['discount_manager_startdate'], $discount['discount_manager_enddate'] ); $inCurrency = supadu_discount_manager_in_currency( $supapress->currency, $discount['discount_manager_currency'] ); $price = supadu_discount_manager_get_price( $supapress->prices, $supapress->currency ); $discountAmount = supadu_discount_manager_real_amount( $price, $discount ); if( $discount['discount_manager_scope'] == 'All' ) { if( $inDateRange && $inCurrency ) { $myDiscounts[$discountAmount] = $discount; } } else { $isbns = explode( ',', $discount['discount_manager_isbns'] ); $inISBNs = !empty( $isbns ) && in_array( $supapress->isbn, $isbns ); if( $inDateRange && $inCurrency && $inISBNs ) { $myDiscounts[$discountAmount] = $discount; } } } } if( !empty( $myDiscounts ) ) { krsort( $myDiscounts ); $myDiscount = reset( $myDiscounts ); if( $returnObject ) { return $myDiscount; } $myDiscount = $myDiscount['discount_manager_parameter']; } return $returnObject ? array() : $myDiscount; } /** * @param $startDate * @param $endDate * * @return bool */ function supadu_discount_manager_date_in_range($startDate, $endDate) { $return = true; $today = date( 'Ymd' ); if( isset( $startDate ) && $startDate !== '' ) { $return = $return && $startDate <= $today; } if( isset( $endDate ) && $endDate !== '' ) { $return = $return && $endDate >= $today; } return $return; } /** * @param $currency * @param $discountCurrency * * @return bool */ function supadu_discount_manager_in_currency($currency, $discountCurrency) { return $currency === $discountCurrency || $discountCurrency === 'All'; } /** * @param $price * @param $discount * * @return string */ function supadu_discount_manager_real_amount($price, $discount) { if( $discount['discount_manager_type'] === 'Flat' ) { $return = number_format( $discount['discount_manager_value'], 2 ); } elseif( $discount['discount_manager_type'] === 'Percentage' ) { $return = number_format( ( $discount['discount_manager_value'] * $price ) / 100, 2 ); } else { $return = false; } if( $return !== false ) { $return = number_format($price - $return,2); } else { $return = null; } return $return; } /** * @param $prices * @param $currency * * @return mixed */ function supadu_discount_manager_get_price($prices, $currency) { $price = false; if( !empty( $prices ) && $currency !== '' ) { foreach( $prices as $value ) { if( $value->locale === $currency ) { $price = $value->amount; break; } } } return $price; } Homepage - Pluto Press
Pluto Press Logo

Books

Authors

Events

On the Blog

Final Blog Test

Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion daikon amaranth tatsoi tomatillo melon azuki bean garlic.

Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette tatsoi pea...

Read full article
A collection of essays written by Chomsky in the late 1990s, all of which subvert the United States foreign policy discourse
View

Nirmalangshu Mukherji

This is the description (override)

VIEW
Test

get-political

The Get Political series is a response to the unconvincing and desperate rhetoric from politicians on both sides of the Atlantic. As the crisis of neoliberalism develops, the established order becomes ever more helpless to improve things.
These...

VIEW

Pluto MERCHANDISE
We have a range of Pluto
totes on sale now

This is a promotion block that I have typed content into!
An independent publisher of radical, left-­‐wing non-­‐fiction books. Established in 1969, we are one of the oldest radical publishing houses in the UK, but our focus remains making timely interventions in contemporary struggles.
Nulla quis sem eu risus ornare maximus vel ut leo.

BURNING COUNTRY IN NORTH AMERICA

To promote the publication of Burning Country: Syrians in Revolution
and War, authors Robin Yassin-Kassab and Leila Al-Shami are
embarking on an extended tour of North America.

Read full article

Owen Hatherley introduces ‘THE CHAPLIN MACHINE’

Owen Hatherley talks about his book ‘The Chaplin Machine: Slapstick,
Fordism and the Communist Avant-Garde’.

Watch Video

BURNING COUNTRY IN NORTH AMERICA

To promote the publication of Burning Country: Syrians in Revolution
and War, authors Robin Yassin-Kassab and Leila Al-Shami are
embarking on an extended tour of North America.

Read full article

BURNING COUNTRY IN NORTH AMERICA

To promote the publication of Burning Country: Syrians in Revolution
and War, authors Robin Yassin-Kassab and Leila Al-Shami are
embarking on an extended tour of North America.

Read full article

Owen Hatherley introduces ‘THE CHAPLIN MACHINE’

Owen Hatherley talks about his book ‘The Chaplin Machine: Slapstick,
Fordism and the Communist Avant-Garde’.

Watch Video

ACTIVESTILLS: How Photography Can Become A Means Of Protest – Test

Visual activism, including activist or struggle photography, can be seen
as offering a response to the radical critique that photojournalism and
documentary photography faced in the 1980s by critics such as Martha
Rosler and Allan...

Read full article
Author David Randall in conversation with Anamik Saha’

Author David Randall in conversation with Anamik Saha’

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eu pellentesque augue. Etiam sagittis pulvinar lectus, in commodo urna vehicula id. Cras dignissim ullamcorper urna ut tempus. In sed laoreet mauris

Lorem ipsum dolor sit...

MORE INFO & TICKETS
Read More