PCP-20 / show buttons when products_page shortcode is used

This commit is contained in:
David Remer 2020-07-10 10:07:00 +03:00
parent 329e2a47a0
commit 93d70249c7

View file

@ -52,6 +52,10 @@ class SmartButton implements SmartButtonInterface
{ {
$buttonRenderer = static function () { $buttonRenderer = static function () {
$product = wc_get_product();
if ($product->is_type(['external', 'grouped'])) {
return;
}
echo '<div id="ppc-button"></div>'; echo '<div id="ppc-button"></div>';
}; };
@ -60,6 +64,10 @@ class SmartButton implements SmartButtonInterface
if (! $canRenderDcc) { if (! $canRenderDcc) {
return; return;
} }
$product = wc_get_product();
if ($product->is_type(['external', 'grouped'])) {
return;
}
if (!$id) { if (!$id) {
$id = 'ppcp-hosted-fields'; $id = 'ppcp-hosted-fields';
} }
@ -108,32 +116,26 @@ class SmartButton implements SmartButtonInterface
$notEnabledOnProductPage = $this->settings->has('button_single_product_enabled') && $notEnabledOnProductPage = $this->settings->has('button_single_product_enabled') &&
!$this->settings->get('button_single_product_enabled'); !$this->settings->get('button_single_product_enabled');
if ( if (
is_product() (is_product() || wc_post_content_has_shortcode('product_page'))
&& !$notEnabledOnProductPage && !$notEnabledOnProductPage
) { ) {
$product = wc_get_product();
if (! $product->is_type(['external', 'grouped'])) {
add_action( add_action(
'woocommerce_single_product_summary', 'woocommerce_single_product_summary',
$buttonRenderer, $buttonRenderer,
31 31
); );
} }
}
if ( if (
is_product() (is_product() || wc_post_content_has_shortcode('product_page'))
&& $this->settings->has('dcc_single_product_enabled') && $this->settings->has('dcc_single_product_enabled')
&& $this->settings->get('dcc_single_product_enabled') && $this->settings->get('dcc_single_product_enabled')
) { ) {
$product = wc_get_product();
if (! $product->is_type(['external', 'grouped'])) {
add_action( add_action(
'woocommerce_single_product_summary', 'woocommerce_single_product_summary',
$dccRenderer, $dccRenderer,
31 31
); );
} }
}
$notEnabledOnMiniCart = $this->settings->has('button_mini_cart_enabled') && $notEnabledOnMiniCart = $this->settings->has('button_mini_cart_enabled') &&
!$this->settings->get('button_mini_cart_enabled'); !$this->settings->get('button_mini_cart_enabled');
if ( if (
@ -308,7 +310,7 @@ class SmartButton implements SmartButtonInterface
private function context(): string private function context(): string
{ {
$context = 'mini-cart'; $context = 'mini-cart';
if (is_product()) { if (is_product() || wc_post_content_has_shortcode('product_page')) {
$context = 'product'; $context = 'product';
} }
if (is_cart()) { if (is_cart()) {