context = adp_context(); $this->customizer = $contextOrCustomizer instanceof CustomizerExtensions ? $contextOrCustomizer : $customizerOrEngine; $this->engine = $customizerOrEngine instanceof Engine ? $customizerOrEngine : $deprecated; $this->rangeDiscountTable = Factory::get("VolumePricingTable_RangeDiscountTable", $this->customizer, $this->engine); } public function withContext(Context $context) { $this->context = $context; } public function installRenderHooks() { add_action('wp_loaded', function () { $themeOptions = $this->customizer->getThemeOptions(); if ($this->context->getOption('show_matched_bulk_table')) { $actions = array($themeOptions->productBulkTable->options->tablePositionAction); foreach (apply_filters('wdp_product_bulk_table_action', $actions) as $action) { add_action($action, array($this, 'echoProductTableContent'), 50, 0); } } if ($this->context->getOption('show_category_bulk_table')) { $actions = array($themeOptions->categoryBulkTable->options->tablePositionAction); foreach (apply_filters('wdp_category_bulk_table_action', $actions) as $action) { add_action($action, array($this, 'echoCategoryTableContent'), 50, 0); } } if ( $this->context->getOption('show_matched_bulk_table') || $this->context->getOption('show_category_bulk_table') ) { $this->loadAssets(); } }); } public function echoProductTableContent() { global $product; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $this->getProductTableContent($product); } public function getProductTableContent($product, $ruleId = null): string { if ($product instanceof \WC_Product_Variable) { return $this->getTableContentWithDefaultVariation($product, $ruleId); } else { return $this->rangeDiscountTable->getProductTableContent($product, [], $ruleId); } } protected function getTableContentWithDefaultVariation(\WC_Product_Variable $product, $ruleId = null): string { $attributes = []; foreach ($product->get_variation_attributes() as $attrName => $options) { $queryKey = wc_variation_attribute_name($attrName); //phpcs:ignore WordPress.Security.NonceVerification.Recommended if (isset($_GET[$queryKey])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput $attributes[$queryKey] = wc_clean(wp_unslash($_GET[$queryKey])); } else { $attributes[$queryKey] = $product->get_variation_default_attribute($attrName); } } $variationId = \WC_Data_Store::load('product')->find_matching_product_variation($product, $attributes); return $this->rangeDiscountTable->getProductTableContent($variationId, $attributes, $ruleId); } public function echoCategoryTableContent() { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo $this->rangeDiscountTable->getCategoryTableContent(); } public function loadAssets() { add_action('wp_print_styles', array($this, 'hookLoadAssets')); } public function hookLoadAssets() { $context = $this->context; $baseVersionUrl = WC_ADP_PLUGIN_URL . "/BaseVersion/"; wp_enqueue_style('wdp_pricing-table', $baseVersionUrl . 'assets/css/pricing-table.css', array(), WC_ADP_VERSION); wp_enqueue_style('wdp_deals-table', $baseVersionUrl . 'assets/css/deals-table.css', array(), WC_ADP_VERSION); if ($context->is($context::WC_PRODUCT_PAGE) || $context->is($context::PRODUCT_LOOP)) { wp_enqueue_script( 'wdp_deals', $baseVersionUrl . 'assets/js/frontend.js', ['jquery'], WC_ADP_VERSION, true ); } $scriptData = array( 'ajaxurl' => admin_url('admin-ajax.php'), 'js_init_trigger' => apply_filters('wdp_bulk_table_js_init_trigger', ""), ); wp_localize_script('wdp_deals', 'script_data', $scriptData); } }