PluginProbe
Tiered Pricing Table for WooCommerce / 8.1.0
Tiered Pricing Table for WooCommerce v8.1.0
8.1.0 8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 All 92 releases
tier-pricing-table / src / Addons / GlobalTieredPricing / CPT / PricingTestLinks.php

PricingTestLinks.php in Tiered Pricing Table for WooCommerce 8.1.0, at src/Addons/GlobalTieredPricing/CPT/PricingTestLinks.php

49 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace TierPricingTable\Addons\GlobalTieredPricing\CPT;
2
3 use TierPricingTable\Addons\GlobalTieredPricing\GlobalPricingRule;
4 use TierPricingTable\Addons\Tools\PricingTest\PricingTester;
5 use WP_Post;
6
7 /**
8 * Links from the pricing rules list to the Pricing test utility (Tools add-on): a button next to
9 * "Add Pricing Rule" and a "Test" row action. The rule editor links from its Rule status box.
10 */
11 class PricingTestLinks {
12
13 public function __construct() {
14 add_filter( 'post_row_actions', array( $this, 'addRowAction' ), 20, 2 );
15 add_action( 'admin_footer-edit.php', array( $this, 'addListButton' ) );
16 }
17
18 public function addRowAction( $actions, WP_Post $post ) {
19 if ( GlobalTieredPricingCPT::SLUG !== $post->post_type || ! PricingTester::isAvailable() ) {
20 return $actions;
21 }
22
23 // a skipped rule changes nothing, so there is nothing to test
24 if ( 'publish' === $post->post_status && 'skipped' === GlobalPricingRule::build( $post->ID )->getEffectiveStatus() ) {
25 return $actions;
26 }
27
28 // a new tab: the test is a side trip from the list or the editor, and the editor may hold unsaved changes
29 $actions['tpt_pricing_test'] = sprintf( '<a href="%s" target="_blank" rel="noopener">%s</a>', esc_url( PricingTester::getUrl( $post->ID ) ), esc_html__( 'Test', 'tier-pricing-table' ) );
30
31 return $actions;
32 }
33
34 public function addListButton() {
35 $screen = get_current_screen();
36
37 if ( ! $screen || GlobalTieredPricingCPT::SLUG !== $screen->post_type || ! PricingTester::isAvailable() ) {
38 return;
39 }
40 ?>
41 <script>
42 jQuery( function ( $ ) {
43 $( '.wrap .page-title-action' ).first().after( ' <a href="<?php echo esc_url( PricingTester::getUrl() ); ?>" class="page-title-action"><?php echo esc_js( __( 'Pricing test', 'tier-pricing-table' ) ); ?></a>' );
44 } );
45 </script>
46 <?php
47 }
48 }
49