| 1 |
<?php |
| 2 |
|
| 3 |
namespace Depicter\Document\Models\Elements; |
| 4 |
|
| 5 |
use Averta\Core\Utility\Data; |
| 6 |
|
| 7 |
class WooAddToCart extends Button { |
| 8 |
|
| 9 |
public function getDefaultAttributes() |
| 10 |
{ |
| 11 |
$defaultAttributes = parent::getDefaultAttributes(); |
| 12 |
$product = $this->getDataSheet()['post'] ?? null; |
| 13 |
if ( $product ) { |
| 14 |
$defaultAttributes['data-product-id'] = $product->ID; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! empty( $this->options->canUseAjax) ) { |
| 18 |
$defaultAttributes['data-can-use-ajax'] = $this->maybeReplaceDataSheetTags( $this->options->canUseAjax ) ? 'true' : 'false'; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! empty( $this->options->purchasable) ) { |
| 22 |
$defaultAttributes['data-purchasable'] = $this->maybeReplaceDataSheetTags( $this->options->purchasable ) ? 'true' : 'false'; |
| 23 |
} |
| 24 |
|
| 25 |
if ( ! empty( $this->options->useAjax) ) { |
| 26 |
$defaultAttributes['data-use-ajax'] = Data::cast( $this->options->useAjax, 'bool' ) ? 'true' : 'false'; |
| 27 |
} |
| 28 |
|
| 29 |
if ( ! empty( $this->options->cartPageLabel) ) { |
| 30 |
$defaultAttributes['data-added-label'] = $this->options->cartPageLabel; |
| 31 |
} |
| 32 |
|
| 33 |
$defaultAttributes['data-cart-page'] = wc_get_cart_url(); |
| 34 |
|
| 35 |
return $defaultAttributes; |
| 36 |
} |
| 37 |
} |
| 38 |
|